Directory |
Name | Description |
---|---|
SearchOption | Specifies whether to search the current directory, or the current directory and all subdirectories. |
Name | Description |
---|---|
CreateDirectory | Creates a directory and any subdirectories in the specified path. |
Delete | Deletes directories and files within directories. |
Exists | Checks if the path exists. |
GetCreationTime | Returns the time of creation for the specified directory in local time. |
GetCreationTimeUtc | Returns the time of creation for the specified directory in UTC time. |
GetCurrentDirectory | Returns the current directory the application is set to. |
GetDirectories | Returns a list of all the directories found in the specified directory that matches the search pattern. |
GetDirectoryRoot | Returns the root directory of the specified path. |
GetFiles | Returns a list of all the files that match a pattern within the specified directory. |
GetFileSystemEntries | Returns both directories and files that match the specified pattern. |
GetLastAccessTime | Returns the time the directory was last accessed in local time. |
GetLastAccessTimeUtc | Returns the time the directory was last accessed in UTC time. |
GetLastWriteTime | Returns the time the directory was last written to in local time. |
GetLastWriteTimeUtc | Returns the time the directory was last written to in UTC time. |
GetLogicalDrives | Returns a list of the logical drives installed on this machine. |
GetParent | Returns the parent of the specified directory. |
Move | Moves a directory and all of its contents to another location. |
SetCreationTime | Sets the creation time of the specified directory to the local time. |
SetCreationTimeUtc | Sets the creation time of the specified directory to UTC time. |
SetCurrentDirectory | Changes the current directory to the specified directory. |
SetLastAccessTime | Sets the time the directory was last accessed in local time. |
SetLastAccessTimeUtc | Sets the time the directory was last accessed in UTC time. |
SetLastWriteTime | Sets the time the directory was last written to in local time. |
SetLastWriteTimeUtc | Sets the time the directory was last written to in UTC time. |
Use the Directory class for typical operations such as copying, moving, renaming, creating, and deleting directories. You can also use the Directory class to get and set DateTime information related to the creation, access, and writing of a directory.
The following code example determines whether a specified directory exists, deletes it if it exists, and creates it if it does not exist. This example then moves the directory, creates a file in the directory, and counts the files in the directory.
Public Sub Main() Const Source As String = "c:\MyDir" Const Target As String = "c:\TestDir" On Error GoTo Catch If Not Directory.Exists(Source) Then Directory.CreateDirectory Source End If File.CreateText Path.Combine(Source, "MyDirFile.txt") If Directory.Exists(Target) Then Directory.Delete Target, True End If Directory.Move Source, Target File.CreateText Path.Combine(Target, "TestDirFile.txt") Debug.Print CorString.Format("The number of files in {0} is {1}", _ Target, CorArray.Length(Directory.GetFiles(Target))) Exit Sub Catch: Dim Ex As Exception Catch Ex, Err Debug.Print "The process failed: " & Ex.Message End Sub