Send to Recycle Bin with VB
In VB you can use the Kill statement to delete files quickly but you lose the ability to retrieve the files easily. We will see how to delete files to the Recycle Bin that can be recovered.
You can use Visual Basic's Kill statement to delete files from a disk. You can also use the methods that are associated with the FileSystemObject class in the Windows Scripting Runtime. Both of these methods have the shortcoming that they delete a file permanently; in other words, they don't delete the file to the Windows Recycle Bin, from which it can be restored.
To delete a file to the Recycle Bin, use the SHFileOperation API function. This function takes as its one argument a user-defined type (UDT) that contains information (such as the filename) about the operation to perform.You can see the definition of the UDT in the sample code that follows. To delete a file, you must include three pieces of information in the UDT: the name of the file, a flag specifying a delete operation, and another flag specifying that the delete is to be undoable.
The following code shows how this is done. Place this code in a code module in your project, and then call the DeleteFileToRecycleBin procedure, passing the name (including the path) of the file to be deleted.
|All times are GMT +5.5. The time now is 21:23.|