Batch rename files perl




















Have you ever wanted to be able to rename a group of files based on a regular expression? Well the script below will let you do just that. Save the above code into a file called rename. Make sure that the permissions are set correctly so that you can execute the script. If Perl is somewhere else, you'll need to change the first line to point to where Perl is installed on your system. You can actually pass any Perl expression through to perlexpr allowing you to do more complex file renaming actions.

The files argument is a list of filenames that you want to change. Change all the files prefixed with the text mah and suffixed with. The possibilities are endless. Common functions [ edit ] Most batch renamers share a basic set of functions to manipulate the filenames: Find a string within the filename and replace it with another, or remove it. Setting the capitalization of the letters in the filenames. Extracting information from the files, such as Mp3ID3 tags, and putting it in the filename.

Add a number sequence ,,, Use a text file as a source for new file names. Common uses [ edit ] There are many situations where batch renaming software can be useful.

Using a batch renamer the photographer can easily give the pictures meaningful names. When downloading files from the Internet such as mp3 music, the files often have crude names. A batch renamer can be used to quickly change the filenames to a style that suits the person who downloaded them.

When managing large amount of files, such as a picture database, a batch renamer is more or less essential for the task of maintaining filenames without too much manual labour. When uploading files to a web server or transferring the files to an environment that does not support space or non-English characters in filenames, a batch renamer can be used to substitute such characters with acceptable ones.

Check man mv for complete info on those switches. That is, you want to change the trailing cfg to conf. Or you could run this lengthy command:. There is a more elegant and solution, though.

The command would simply be:. Use the -v option if you want to see some verbose output of what is going on with that command. Note that the curly braces could appear anywhere. Suppose you want to replace 10 with 00 in the previous renaming command:.

Since we are now renaming multiple files at once potentially hundreds, thousands or even more , the output of most examples have been truncated to take less space. We have left just enough output to make them understandable. JPG to. This way, each single image with the extension. JPG is assigned, one on each iteration of the loop, to the variable img.

JPG , it will become We then add the lowercase. The following command will lowercase the entire filename not only the extension, like our previous example :.

This is what returns any characters from the filename in lowercase. I was able to just search for ,, and I could easily find this specific part of the manual. Now, we have a situation in which we must rename files padding certain number with zeores on the left. For instance 1 becomes 01, 2 becomes 02, and so on, until 9 which becomes So, imagine we have these files:.



0コメント

  • 1000 / 1000