Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

My.Computer.FileSystem.GetFiles Method 

Returns a read-only collection of strings representing the names of files within a directory.


' Usage
Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(directory)
Dim value As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Computer.FileSystem.GetFiles(directory ,searchType ,wildcards)
' Declaration
Public Function GetFiles( _
   ByVal directory As String _
) As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
' -or-
Public Function GetFiles( _
   ByVal directory As String, _
   ByVal searchType As SearchOption, _
   ByVal wildcards As String() _
) As System.Collections.ObjectModel.ReadOnlyCollection(Of String)

Parameters

directory

String. Directory to be searched. Required.

searchType

SearchOption Enumeration. Whether to include subfolders. Default is SearchOption.SearchTopLevelOnly. Required.

wildcards

String. Pattern to be matched. Required.

Read-only collection of strings.

The following conditions may cause an exception:

An empty collection is returned if no files matching the specified pattern are found.

The following table lists examples of tasks involving the My.Computer.FileSystem.GetFiles method.

To See

Get the collection of files in a directory

How to: Get the Collection of Files in a Directory in Visual Basic

Find files with a specific pattern in a directory

How to: Find Files with a Specific Pattern in Visual Basic

The following example returns all files in the directory and adds them to ListBox1.

For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments)
ListBox1.Items.Add( foundFile )
Next

This example requires that you have a ListBox named ListBox1 on your form.

This example returns all files in the directory with the extension .dll and adds them to ListBox1.

For Each foundFile As String In My.Computer.FileSystem.GetFiles _
(My.Computer.FileSystem.SpecialDirectories.MyDocuments, True, "*.dll")
ListBox1.Items.Add( foundFile )
Next

This example requires that you have a ListBox named ListBox1 on your form.

Namespace: Microsoft.VisualBasic.MyServices

Class: FileSystemProxy (provides access to FileSystem)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Project type Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

The following permission may be necessary:

Permission Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.