1

How to move file/dir to trash and restore them to original location afterwards?. Most answers on stackoverflow are for Windows or Mac OS. And some suggest to implement using linux commands.

Is there any C api that can perform this actions?

  • 4
    Linux doesn't have a "recycle bin", but some windowing environments (e.g. Gnome, KDE) do. Do you mean something like that? – possum May 06 '20 at 11:16
  • 1
    On Ubuntu, for example, the trash location is described here: [Where is the trash folder?](https://askubuntu.com/questions/102099/where-is-the-trash-folder) – lurker May 06 '20 at 11:35
  • @SeamusR Yes. In gnome when we delete it goes to trash dir. I would like to do it using C. – Prabhakar Tayenjam May 06 '20 at 11:47

1 Answers1

1

If you're looking for GNOME take a look at the C implementation of nautilus which links into that system and does things programmatically

https://gitlab.gnome.org/GNOME/nautilus/-/blob/master/src/nautilus-file-utilities.c

and the gio source which is a command line tool written in C which shows you how to get GFile objects which contain this

https://github.com/GNOME/glib/blob/master/gio/gio-tool-list.c https://developer.gnome.org/gio/stable/GFile.html#g-file-new-for-path

In particular, you will want the original locations which is in the file type used there

file->details->trash_orig_path

possum
  • 1,837
  • 3
  • 9
  • 18