#!/usr/bin/perl -w #---------------------------------------------------------------------- # indexcfgs.pl - utility to rename files in the current directory to an # indexed format so that a unique index number is # prepended to the current file name. The naming # template is: # # DDDDD- # # Usage: create the *.cfg file you need, with any name and .cfg # extension. Run this script and it will automatically # rename your file to the indexed format above. # # Author: Daniel BORNAZ $max_index){ $max_index=$crt_index; } $counter_indexed++; }else{ @queue=($file,@queue); $counter_queue++; } } # set the next index number $max_index++; # index the enqueued file names foreach my $file (@queue){ my $newname; $newname=sprintf("%05d-%s",$max_index++,$file); system("mv",$file,$newname) == 0 or die "Cannot rename $file to $newname: $?"; } printf("$counter_queue files indexed, ". "$counter_indexed files already indexed. Done.\n"); } #-------------------------------------------------------------------- # display usage help # sub print_usage { print "\n"; print " ./indexcfgs.pl [--strip]\n"; print " no params: Index the *.cfg file names in current dir\n"; print " to DDDDD-\n"; print " --strip: Strips the index from the *.cfg file names ". "in current dir\n"; print "\n"; exit 0; } #--- Program starts here -------------------------------------------- GetOptions(\%args, "strip" => \$opt_strip, "help" => \$opt_help, ); if(defined($opt_help)){ print_usage(); } if(defined($opt_strip)){ strip_file_names(); }else{ index_file_names(); }