GetFiles Method


GetFiles Method

Location

My.Computer.FileSystem.GetFiles

Syntax

     Dim result As System.Collections.ObjectModel.ReadOnlyCollection( _        Of String) = My.Computer.FileSystem.GetFiles( _    path[, searchType, wildcard]) 


path (required; String)

The path to the directory that includes the files to return.


searchType (optional; SearchOption enumeration)

The type of search to perform. One of the following Microsoft.VisualBasic.FileIO.SearchOption enumeration values.

Value

Description

SearchAllSubDirectories

Includes all files found directly under the specified path and also in all descendant subdirectories below the specified path

SearchTopLevelOnly

Includes only those files found immediately under the specified path; does not include files found in other descendant subdirectories


If this parameter is missing, it defaults to SearchTopLevelOnly.


wildcard (optional; String)

A pattern used to match file names. If missing, all names are matched. Use the asterisk character (*) to match zero or more characters or the question mark character (?) to match exactly one character.

Description

The GetFiles method returns a collection of strings, each one the name of a file within the specified directory. If no files are found or match the specified wildcard, an empty collection is returned.

Usage at a Glance

  • The returned collection is read-only.

  • An exception is thrown if the supplied path is missing or invalid or if an invalid wildcard expression appears.

  • An exception is thrown if the user lacks sufficient file-system privileges.

  • Each returned file name includes the full path to that file, not just the relative file name.

Example

The following example lists all files in the current directory.

     Dim fileList As String = ""     Dim currentDir As System.Collections.ObjectModel. _        ReadOnlyCollection(Of String) = _        My.Computer.FileSystem.GetFiles(".")     For Each oneFile As String In currentDir        fileList &= "|" & oneFile     Next oneFile     MsgBox("The current directory contains the following " & _        "files:" & Replace(fileList, "|", vbCrLf)) 

Related Framework Entries

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles Method

  • Microsoft.VisualBasic.FileIO.FileSystem.GetFiles Method

  • System.IO.Directory.GetFiles Method

See Also

CurrentDirectory Property, Drives Property, FileSystem Object, FindInFiles Method, GetDirectories Method, GetDirectoryInfo Method, GetDriveInfo Method, GetFileInfo Method, GetTempFileName Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net