Moving files to Trash Can in Linux using C++ Moving files to Trash Can in Linux using C++ linux linux

Moving files to Trash Can in Linux using C++


Why not find a terminal command to move the files and then call system() to run it for you inside your C++ program?

This might (I haven't tested it) be a possible one-liner in Linux to move files to the trash via the terminal. You would just pass the command as a quoted string to system() and call it in your C++ implementation.


The answer is in

http://www.freedesktop.org/wiki/Specifications/trash-spec

For every user a “home trash” directory MUST be available. Its name and location are $XDG_DATA_HOME/Trash

you only need to write C++ code move your file into such directory.

You can move files using boost file system and you can retrieve the XDG_DATA_HOME value using cstlib getenv.


As far as I know there's no standard trash can in Linux in the first place.