Engos
Engos

Reputation: 306

Moving files to Trash Can in Linux using C++

I'm trying to move (delete) a file to a Trash Can (in Linux) using C++ (also using QT4 for GUI). Unfortunately it seems to be quite difficult to do so and as far as I can tell there isn't a unified API for it.

I would like for my application to run not only on KDE but on GNOME, Xfce and other Linux desktop environments. That's why I'm searching for a more universal approach.

The best I could find so far is:

I would be happy with any approach that requires as little desktop environment specific code as possible. Or in other words that's as much independent from KDE/GNOME/Xfce components as possible.

Any help in finding a solution (if there even is one) would be greatly appreciated.

Upvotes: 13

Views: 2642

Answers (3)

rodrigob
rodrigob

Reputation: 2927

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.

Upvotes: 1

kevlar1818
kevlar1818

Reputation: 3125

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.

Upvotes: 1

dascandy
dascandy

Reputation: 7302

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

Upvotes: 0

Related Questions