Utilize the Full Functionality of the Whidbey File Management - More Classes and Public Methods
(Page 3 of 8 )
Some of the public methods used for Directory class are described as follows.
- CreateDirectory – Creates a new directory in a specified path.
- Delete - Delete the directory from the specified path
- Exists – Checks whether the associated directories exists in the specific path
- GetCreationTime – Get the creation time of directory
- GetCreationTimeUtc – Get the creation time in universal coordinated time
- GetCurrentDirectory – Get the current working directory of the application
- GetDirectories – Gets the name of subdirectories in the working folder
- GetDirectoryRoot – Get root and volume information for the specified path
- GetFiles - Get or returns all the files listed in the specified directory
- GetFileSytemEntries - Get or returns all the files and sub directories listed in the specified directory
- GetLastAccessTime – Last access date and time of the specified directory
- GetLastAccessTimeUtc – Last access date and time of the specified directory in universal coordinator time (UTC) format
- GetLastWriteTime – Last written date and time of a specified directory
- GetLastWriteTimeUtc – Last written date and time of a specified directory in universal coordinator time (UTC)
- GetLogicalDrives – Get all the logical drives on the computer
- GetParent – Get the absolute and relative path of the parent directory
- Move – Move the specific directory to another location
- SetCreationTime – Sets the creation date and time for the specified directory or file
- SetCreationTimeUtc – Sets the creation date and time for the specified directory or file in universal coordinated time format
- SetCurrentDirectory – Sets the current directory to a specified directory in an application path
- SetLastAccessTime - Sets the last access date and time for the specified directory or file
Usage:
‘ Checking whether the directory exists in the specified path
Dim strMyPath as String = “C:\mySample”
If Directory.Exists(strMyPath) = True then
Directory.Delete(strMyPath)
Else
Directory.CreateDirectory (strMyPath)
End if
5. The class DirectoryInfo used the same functionality as Directory class except if you are not going to reuse an object several times.
6. The class DirectoryNotFoundException throws exception error when the file or directory not found in the specified path.
7. The class EndOfStreamException throws exception error at the past the end of a stream.
8. The class ErrorEventArgs provides data for Error event.
Usage:
‘ Checking whether the directory exists in the specified path
Dim strMyPath as String = “C:\mySample”
‘ Initializes the “objException” Exception object
Dim objException as New Exception(“Cannot create Directory”)
‘ Creates an ErrorEventArgs with the exception.
Dim objErrorEventArgs as New ErrorEventArgs(objException)
If Directory.Exists(strMyPath) = True then
Directory.Delete(strMyPath)
Else
Directory.CreateDirectory (strMyPath)
End if
‘ Retrieves Exception from ErrorEventArgs
Dim objReturnedException as Exception= objErrorEventArgs.GetException()
If objReturnedException.Message <> “” then
MessageBox.Show(objReturnedException.Message
End if
End Sub
9. The class File provides to manage the file manipulation operations such as Creating, Opening, Deleting, Copying and Moving of files using FileStream objects. File class methods are static.
Next: Public Methods with File Class >>
More .NET Articles
More By Benoyraj Baskaran