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)
- 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.
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, _
FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
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)
Availability by Project Type
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:
For more information, see Code Access Security and Requesting Permissions.
Tasks
Reference