Advertisement
Guest User

devilzc0de rulez !!! perl jumping script (CLI)

a guest
Feb 7th, 2012
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.11 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. # devilzc0de.org (c) 2012
  3. use File::Basename;
  4. use File::Copy;
  5.  
  6. if(($#ARGV != 0) && ($#ARGV != 1)){
  7.     print "usage : perl ".basename($0)." [path to dir/file] [path to save file]\r\n";
  8.     print "ex    : perl ".basename($0)." /etc\r\n";
  9.     print "ex    : perl ".basename($0)." /etc/issue\r\n";
  10.     print "ex    : perl ".basename($0)." /etc/issue issue_new_copy\r\n";
  11.     exit;
  12. }
  13.  
  14. $target = @ARGV[0];
  15. $target =~ s/\\/\//g;
  16.  
  17. if(-d $target){
  18.     if(!($target =~ /.*\/+$/)){
  19.         $target = $target."/";
  20.     }  
  21.     if(opendir(DIR,$target)){
  22.         while($file = readdir(DIR)){
  23.             if(($file eq ".") || ($file eq "..")){ next; }
  24.             $fs = "";
  25.             if(-d $target.$file){
  26.                 $fs = "[ DIR ]";
  27.             }
  28.             elsif(-f $target.$file){
  29.                 $fs = (-s $target.$file);
  30.             }
  31.              print sprintf("%12s", $fs)." ".$file."\r\n";
  32.         }
  33.         closedir(DIR);
  34.     }
  35.  
  36. }
  37. elsif(-f $target){
  38.     if($#ARGV == 1){
  39.         copy($target, @ARGV[1]);
  40.     }
  41.     else{
  42.         if(open(FILE,$target)){
  43.             binmode FILE;
  44.             while (($n = read FILE, $data, 1024) != 0) {
  45.                 print $data;
  46.             }
  47.             close(FILE);
  48.         }
  49.     }
  50. }
  51. else{
  52.     print "Can't found file or folder : ".$target;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement