FileSystem.DeleteFile Method (String, UIOption, RecycleOption, UICancelOption)
Deletes a file.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
public static void DeleteFile( string file, UIOption showUI, RecycleOption recycle, UICancelOption onUserCancel )
- Type: System.String
Name and path of the file to be deleted.
- Type: Microsoft.VisualBasic.FileIO.UIOption
Whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs.
- Type: Microsoft.VisualBasic.FileIO.RecycleOption
Whether or not the deleted file should be sent to the Recycle Bin. Default is RecycleOption.DeletePermanently.
- Type: Microsoft.VisualBasic.FileIO.UICancelOption
Specifies whether or not an exception is thrown when the user cancels the operation. Default is UICancelOption.ThrowException.
The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; it has a trailing slash where a file must be specified; or it is a device path (starts with \\.\).
file is Nothing or an empty string.
The path exceeds the system-defined maximum length.
A file or directory name in the path contains a colon (:) or is in an invalid format.
The file is in use.
The user lacks necessary permissions to view the path.
The file does not exist.
The user does not have permission to delete the file or the file is read-only.
The user cancelled the operation and onUserCancel is set to UICancelOption.ThrowException.
The showUI, recycle, and onUserCancel parameters are not supported in applications that are not user interactive, such as Windows Services.
The following table lists an example of a task involving the My.Computer.FileSystem.DeleteFile method.
To delete a file
This example deletes the file Test.txt.
This example deletes the file Test.txt and allows the user to confirm that the file should be deleted.
This example deletes the file Test.txt and sends it to the Recycle Bin.