Hey, I have files on my site that have an ' in the filename which I need to remove. What would be the best method of removing these automatically? For exampe: Gun N' Roses - Sweet Child 'o Mine.gp3 Needs to have all the ' removed... I cant do this manually as there are well over a 1000 files that need to be renamed... Anyway thanks in advance for any input
Hi, Am not an expert in perl scripting but managed to write one for you. Note sure you already got it or not , anyway here is the code #!/usr/bin/perl use strict; use warnings; sub rnfile{ my $new; $new = "@_"; my $old=$new; print "Old Name :$new\n"; $new =~s/'//g; print "New Name : $new\n"; if($old ne $new){ system "mv \"$old\" \"$new\""; } } sub rndir{ my @file =glob "*"; foreach (@file) { rnfile $_; } } rndir; Code (markup): Please save it as .pl file and execute using perl , please be in the folder where all the files are located. Thanks, Ciril
You might be able to do it right from the command line if all the files are in the same directory: perl -i -e -p 's/\'//g' * should do it. Caveat emptor.
Sorry, just reread your post and you're renaming files - so my command won't do that. The above command replaces text inside files.
Ah rite awesome Just a question though. Basically the files Im renaming are sheet-music for the guitar. The file structure is as follows: If I place the perl script in "guitar-tabs" and run it, will it change all the file name under it including the subfolders? Or do I have to place the perl script in each and every one of the folders and run them? Thanks
Ok I managed to change that #!/usr/bin/perl use strict; use warnings; # Script to Remove ' from the file names sub rndir; sub rnfile{ my $new; $new = "@_"; my $old=$new; print "Old Name :$new\n"; $new =~s/'//g; print "New Name : $new\n"; if($old ne $new){ system "mv \"$old\" \"$new\""; } } sub printdir{ foreach (@_){ if (-d $_){ rndir $_; } else { rnfile $_; } } } sub rndir{ my @file =glob "@_/*"; foreach (@file) { printdir $_; } } rndir @ARGV; Code (markup): Regards
So with the file structure I mentioned above do I place it in the root folder and run it with "perl remove.pl guitar-tabs"?
Yup, perl remove.pl guitar-tabs I had trial run it many times. But you may first give it trial run aswell.