Directory: SearchOption |
Specifies whether to search the current directory, or the current directory and all subdirectories.
Public Enum SearchOption
If you choose AllDirectories in your search and the directory structure contains a link that creates a loop, the search operation enters an infinite loop.
The following code example lists all of the directories and files that begin with the letter "s" in "c:\". In this example, the SearchOption is used to specify not to search all subdirectories.
Public Sub Main() Const Path As String = "c:\" Const SearchPattern As String = "s*" Dim di As DirectoryInfo Dim Directories() As DirectoryInfo Dim Files() As FileInfo Set di = NewDirectoryInfo(Path) Directories = di.GetDirectories(SearchPattern, SearchOption.TopDirectoryOnly) Files = di.GetFiles(SearchPattern, SearchOption.TopDirectoryOnly) Debug.Print "Directories that begin with the letter ""s"" in " & Path DisplayFileSystemInfo Directories Debug.Print t("\nFiles that begin with the letter ""s"" in ") & Path DisplayFileSystemInfo Files End Sub Private Sub DisplayFileSystemInfo(ByRef Source As Variant) Dim Item As Variant Dim Info As FileSystemInfo For Each Item In Source Set Info = Item Debug.Print CorString.Format("{0,-25} {1,25}", Info.FullName, Info.LastWriteTime) Next End Sub