Moving files to trash / recycle bin instead of permanent deletion?

Is there a method which would allow files to be moved to the trash / recycle bin rather than permanently deleted? It would be ideal to give the user the option to restore files if they change their mind or made a mistake.

ie, instead of targetFile.delete(), something like targetFile.moveToTrash()

I’d be fine if become the default behavior for the delete method. Not sure if others are generating massive amounts of files which should be force deleted to avoid bloat in the recycle bin.

not natively no.
there’s a node module called “trash” that does this but it’s not compatible with UXP AFAIK.

it basically uses an external executable that handles the moving to trash.

options:

  • use a hybrid plugin C++ and JS
  • create your own trash bin logic (custom dir) and move files there / empty it after a while / let user empty it
  • find a way to use command line / external executable (CmdUtil > Recycle) to handle the deletion
1 Like

Thanks @Maher. This would be a very valuable feature to add to UXP’s file system support.

I appreciate those options, but I’m not sure they are feasible. C++ or an external executable add a lot of complexity, and a custom bin could consume significant space that the user may not be aware of.