Resolved A General Question About DeleteFile() vs Old VB6 Kill Command

zunebuggy65

Active member
Joined
Oct 12, 2023
Messages
42
Programming Experience
3-5
In vba and vb6 you could delete a file using the Kill command. I had a program that accidentally deleted some files using Kill and code that contained an error. I quickly found out that it could not be undone and the files were gone permanently. I could not even use Recuva to get it back.

I now am new to VB.net and actually have a need for my program to permanently delete a file (although a being careful to only delete a specific file). Is the VB.net DeleteFile() command a permanent delete or does it send it to a recoverable recycle bin or can it be recovered with a program like Recuva?

Thanks
 
File.Delete does not put the file in Recycle Bin in Windows. If you want that you must use FileSystem.DeleteFile with RecycleOption.SendToRecycleBin, default is RecycleOption.DeletePermanently for that method.
If you're deleting a file on a network share you can't control this, the remote OS manages its own file system and possibly a recycle bin.
 
I have no idea how Recuva works so I can't really say too much on that. It might be that it reads the memory where the file was located so it works as long as that memory has no been overwritten. Deleting a file is really just removing a reference from a table and marking the memory it occupied as available. Actually overwriting that data may not happen for some time, which is why programs intended to securely delete files will overwrite that memory, possibly numerous times.

The method that @JohnH mentioned would generally be called as My.Computer.FileSystem.DeleteFile methods like that use the Windows shell, so they can incorporate shell functionality like displaying a progress dialogue and "deleting" to the Recycle Bin. You would have been able to use the Windows shell yourself in VB6 and also in VB.NET if you wanted to but using the Recycle Bin is a layer above the file system itself, so methods working at a lower level don't know or care about it.
 
Back
Top