Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a file to trash

Tags:

c

I am using rename function (C, under ubuntu) to move file from one folder to another when trying: rename("./t2.c", "./this/then_this/it_works.c"); it works wonders, removes the file from current folder and moves it to the then_this folder under name.

but when i try this: rename("./t2.c", "~/.local/share/Trash/files/it_works.c"); it just doesn't work, but in terminal typing in "cd ~/.local/share/Trash/files/it_works.c" does open the trash bin.

So what i'm trying to do is move a file to trash bin(delete it). Could anyone tell me what i am doing wrong?

like image 713
user1031204 Avatar asked Dec 10 '11 17:12

user1031204


2 Answers

The problem is that ~ only works in the shell. Replace with the full absolute path (e.g. /home/user1031204/.local/...) & re-try.

like image 200
NPE Avatar answered Oct 05 '22 01:10

NPE


realpath() will be helpful here. You may want to look at glob() and wordexp() as well.

like image 41
Duck Avatar answered Oct 05 '22 01:10

Duck