Location My.Computer.FileSystem.DeleteFile Syntax My.Computer.FileSystem.DeleteFile(path[, showUI, _ recycle[, onUserCancel]])
path (required; String) The path to the file to be deleted.
showUI (optional; UIOption enumeration) Indicates whether error or progress dialog windows should appear during the delete. One of the following Microsoft.VisualBasic.FileIO.UIOption enumeration values. Value | Description |
---|
OnlyErrorDialogs | Only shows error dialog boxes; does not display progress | AllDialogs | Shows progress and error dialogs |
If this parameter is missing, OnlyErrorDialogs is used by default.
recycle (optional; RecycleOption enumeration) Indicates the state of the file after it has been deleted. One of the following Microsoft.VisualBasic.FileIO.RecycleOption enumeration values. Value | Description |
---|
DeletePermanently | Permanently deletes the file | SendToRecycleBin | Moves the file to the Recycle Bin |
If this parameter is missing, DeletePermanently is used by default.
onUserCancel (optional; UICancelOption enumeration) The progress window includes a Cancel button. When pressed, the method takes action based on this parameter. One of the following Microsoft.VisualBasic.FileIO.UICancelOption enumeration values. Value | Description |
---|
DoNothing | Aborts the deletion but returns no information indicating that the deletion was cancelled | ThrowException | Throws an exception |
If this parameter is missing, ThrowException is used by default. Description The DeleteFile method deletes the indicated file. Usage at a Glance Visual Basic includes a Kill procedure that also deletes files. An exception is thrown if the path parameter is missing or invalid. An exception is thrown if the file does not exist or is in use. An exception is thrown if the user lacks sufficient file access permissions. Example The following example sends a file to the Recycle Bin. My.Computer.FileSystem.DeleteFile( _ ("C:\workfile.txt", OnlyErrorDialogs, SendToRecycleBin) Related Framework Entries Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile Method Microsoft.VisualBasic.MyServices.FileSystemProxy.DeleteFile Method System.IO.File.Delete Method See Also CopyDirectory Method, CopyFile Method, CreateDirectory Method, DeleteDirectory Method, FileSystem Object, MoveDirectory Method, MoveFile Method, RenameDirectory Method, RenameFile Method |