FileSystem.DeleteFile Method (String)
Deletes a file.
Assembly: Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
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 following table lists examples of tasks involving the My.Computer.FileSystem.DeleteFile method.
To delete a file
To delete all files in a directory
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.