Leo Charre > File-Trash > File::Trash

Download:
File-Trash-1.10.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.10   Source  

NAME ^

File::Trash - move files to trash and restore as well

SYNOPSIS ^

   use File::Trash qw/trash restore/;

   my $trashed_path = trash('~/this_is_boring.txt');
   # returns '/tmp/trash/home/username/this_is_boring.txt'
   
   restore($trashed_path) 
      or die($File::Trash::errstr);
   

   my $abs_trash = $File::Trash::ABS_TRASH;
   # returns '/tmp/trash' by default

   my $trash_count = trash('~/this_is_boring.txt', '~/this_is_boring_2.txt');
   # returns '2'

DESCRIPTION ^

File::Remove apparently does something similar. I don't see example for using File::Remove in a simple manner alike unlink(). Thus, here it is.

The default abs trash dir

The default dir for trash has been chosen as /tmp/trash. The other common sense place would be $ENV{HOME}/.trash, so, why not? What if you are calling this from some script running under a used who does not have ~, like, maybe cron or maybe from some cgi? This is safer. If you want, you can set the dir to be something else..

   $File::Trash::ABS_TRASH = $ENV{HOME}/.trash

This is the same for default abs backup dir.

API ^

No subs are exported by default.

trash()

Ideally this should behave as unlink(). It does not at present.

Argument is a list of paths to files to delete. If more than one file is provided, returns number of files deleted. If one file is provided only, returns abs path to where the file moved. Returns undef in failure, check errors in $File::Trash::errstr.

If the trash destination exists, the file is appended with a dot digit number. So, this really makes sure you don't lose junk.

backup()

Same as trash(), but does not move the file, copies it instead.

restore()

Argument is abs path to file in trash. Attempts to move back to where it was originally. If the restore to destination exists, will not do it and return false. If you provide one argument, returns destination it restored. If you provide an array, returns number of files restored.

   restore('/home/myself/.trash/hi.txt') 
      or die($File::Trash::errstr);

$File::Trash::ABS_TRASH

Default is /tmp/trash

$File::Trash::ABS_BACKUP

Default is /tmp/backup

$File::Trash::DEBUG

Set to true to see some debug info.

$File::Trash::errstr

May hold error string.

CAVEATS ^

In development. Works great as far as I know. This is mean to be POSIX compliant only. That means no windoze support is provided. If you have suggestions, please forward to AUTHOR.

SEE ALSO ^

File::Remove

AUTHOR ^

Leo Charre leocharre at cpan dot org

LICENSE ^

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

DISCLAIMER ^

This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the "GNU General Public License" for more details.

syntax highlighting: