Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.41 KB | None | 0 0
  1. $!/usr/bin/perl
  2.  
  3. $dir = "/path/to/files/with/trailing/slash/";
  4.  
  5. opendir($dh, $dir);
  6.  
  7. while (readdir $dh) {
  8.  
  9.     $new_filename = "yourname.txt";
  10.    
  11.     if (-e "$dir$new_filename") {
  12.  
  13.         print "Error: file already exists ($new_filename)\n";
  14.        
  15.     }
  16.     else {
  17.  
  18.         rename "$dir$_", "$dir$new_$filename";
  19.         print "File $_ renamed to $new_filename\n";
  20.        
  21.     }
  22.    
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement