Java is the key here. I need to be able to delete files but users expect to be able to "undelete" from the recycle bin. As far as I can tell this isn't possible. Anyone know otherwise?
In Java, we can delete a file by using the File. delete() method of File class. The delete() method deletes the file or directory denoted by the abstract pathname. If the pathname is a directory, that directory must be empty to delete.
Delete Temporary Files through the Java Control Panel Click Delete Files on the Temporary Files Settings dialog. The Delete Files and Applications dialog box appears. Click OK on the Delete Files and Applications dialog. This deletes all the Downloaded Applications and Applets from the cache.
With Windows 10 you can automatically empty the Recycle Bin, but still keeping the most recent files (just in case) — here's how. On Windows 10, when you delete files, they're not immediately removed from the hard drive. Instead, they're sent to the Recycle Bin, in case you need to restore them.
Ten years later, with Java 9, finally there is a builtin way to move files to the Trash Bin
java.awt.Desktop.moveToTrash(java.io.File)
:
public boolean moveToTrash(File file)
Moves the specified file to the trash.
Parameters:
file - the file
Returns:
returns true if successfully moved the file to the trash.
The availability of this feature for the underlying platform can be tested with Desktop.isSupported(Desktop.Action.MOVE_TO_TRASH)
.
For various reasons Windows has no concept of a folder that simply corresponds to the Recycle Bin.
The correct way is to use JNI to invoke the Windows SHFileOperation
API, setting the FO_DELETE
flag in the SHFILEOPSTRUCT
structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With