Advertisement
Infra_HDC

temporary rename all files in var subfolder

Oct 25th, 2024
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.65 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # https://stackoverflow.com/questions/2601027/how-can-i-check-if-a-file-exists-in-perl
  3. # https://stackoverflow.com/questions/3455956/how-do-i-get-the-dirname-of-a-file-with-perl
  4. # https://stackoverflow.com/questions/67965882/finding-a-file-in-directory-using-perl-script
  5. use File::Find;
  6. use File::Basename;
  7.  
  8. my $curr_path="var";
  9.  
  10. my @content;
  11. find( \&wanted, $curr_path);
  12.  
  13. for my $b (@content) {
  14.     if (-f $b) {
  15.     $tmp_name = dirname($b)."/1";
  16.     rename $b, $tmp_name or die "$b: 1st rename error";
  17.     rename $tmp_name, $b or die "$b: 2nd rename error";
  18.     }
  19. }
  20.  
  21. exit;
  22.  
  23. sub wanted {
  24.     push @content, $File::Find::name;
  25.   return;
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement