The My.Computer.FileSystem object provides tools for working with drives, directories, and files. The following table summarizes this object’s properties.
PROPERTY | DESCRIPTION |
CurrentDirectory | Gets or sets the fully qualified path to the application’s current directory. |
Drives | Returns a read-only collection of DriveInfo objects describing the system’s drives. |
SpecialDirectories | Returns a SpecialDirectoriesProxy object that has properties giving the locations of various special directories (such as the system’s temporary directory and the user’s MyDocuments directory). See the following section “My.Computer.FileSystem.SpecialDirectories” for more information. |
The following list describes the My.Computer.FileSystem object’s methods:
METHOD | PURPOSE |
CombinePath | Combines a base path with a relative path reference and returns a properly formatted fully qualified path. For example, the following code displays the name of the directory that is the parent of the application’s current directory: MessageBox.Show(My.Computer.FileSystem.CombinePath (My.Computer.FileSystem.CurrentDirectory(), ".."). |
CopyDirectory | Copies a directory. Parameters indicate whether to overwrite existing files, whether to display a progress indicator, and what to do if the user presses Cancel during the operation. |
CopyFile | Copies a file. Parameters indicate whether to overwrite existing files, whether to display a progress indicator, and what to do if the user presses Cancel during the operation. |
CreateDirectory | Creates a directory. This method will create ancestor directories if necessary. |
DeleteDirectory | Deletes a directory. Parameters indicate whether to recursively delete subdirectories, prompt the user for confirmation, or move the directory into the Recycle Bin. |
DeleteFile | Deletes a file. Parameters indicate whether to prompt the user for confirmation or move the file into the Recycle Bin, and what to do if the user presses Cancel while the deletion is in progress. |
DirectoryExists | Returns True if a specified directory exists. |
FileExists | Returns True if a specified file exists. |
FindInFiles | Returns a read-only collection of strings listing files that contain a target string. |
GetDirectories | Returns a string collection listing subdirectories of a given directory. Parameters tell whether to recursively search the subdirectories, and the wildcards to match. |
GetDirectoryInfo | Returns a DirectoryInfo object for a directory. |
GetDriveInfo | Returns a DriveInfo object for a drive. |
GetFileInfo | Returns a FileInfo object for a file. |
GetFiles | Returns a string collection holding the names of files within a directory. Parameters indicate whether the search should recursively search subdirectories, and give wildcards to match. |
GetParentPath | Returns the fully qualified path of a path’s parent. For example, this returns a file’s or directory’s parent directory. |
MoveDirectory | Moves a directory. Parameters indicate whether to overwrite files that have the same name in the destination directory and whether to prompt the user when such a collision occurs. |
MoveFile | Moves a file. Parameters indicate whether to overwrite a file that has the same name as the file’s destination and whether to prompt the user when such a collision occurs. |
OpenTextFieldParser | Opens a TextFieldParser object attached to a delimited or fixed-field file such as a log file. You can use the object to parse the file. |
OpenTextFileReader | Opens a StreamReader object attached to a file. You can use the object to read the file. |
OpenTextFileWriter | Opens a StreamWriter object attached to a file. You can use the object to write into the file. |
ReadAllBytes | Reads all of the bytes from a binary file into an array. |
ReadAllText | Reads all of the text from a text file into a string. |
RenameDirectory | Renames a directory within its parent directory. |
RenameFile | Renames a file within its directory. |
WriteAllBytes | Writes an array of bytes into a binary file. A parameter tells whether to append the data or rewrite the file. |
WriteAllText | Writes a string into a text file. A parameter tells whether to append the string or rewrite the file. |