SHARE
TWEET

setFilenameUcfirst

fazzyx Nov 28th, 2014 (edited) 238 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2. #
  3. # Rename recursive all files from given folder to upper case first
  4. # Use setFilenameUcfirst.pl /path/to/my/template/folder/
  5. #
  6. # @File setFilenameUcfirst.pl
  7. # @Author Claus Fassing
  8. # @Created 28.11.2014 14:14:29
  9. #
  10.  
  11. use File::stat;
  12. use File::Basename;
  13. use strict;
  14.  
  15. my @files;
  16.  
  17. &getFiles(@ARGV);
  18.  
  19. foreach (@files) {
  20.         rename($_, dirname($_) . "/" . ucfirst(basename($_)) );
  21. }
  22.  
  23.  
  24. sub getFiles {
  25.     local *DH;
  26.     my ( $item, $path );
  27.     my $dir = shift;
  28.     opendir( DH, $dir ) or return;
  29.     while ( $item = readdir(DH) ) {
  30.         next if ( -d $item );
  31.  
  32.         $path = (
  33.             ( $dir =~ /\/$/ ) ? ( $dir . $item ) : ( $dir . '/' . $item ) );
  34.  
  35.         push( @files, $path ) if ( -f $path );
  36.         getFiles($path) if ( -d $path );
  37.     }
  38.     closedir(DH);
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top