Rename Script For Renaming File Extensions
This script is something that I built around a regular expression that I found online when trying to solve a problem. The problem in question is when I download .mp3 files and they come over as .MP3 or .Mp3. Since some audio players are more finicky than others, I've built this script to compensate the different naming conventions.
I have also added a couple of video and image extensions as a starter.
Eventually I want to pair this script with the MP3 Download Script, so I do not have to invoke two different scripts separately. The nice thing about this script, is it will skip over nonexistent .MP4 (for example), if there are no such files in the current directory, then the script will skip right over the line and move on. You'll get something along the lines of this, but it'll work just fine:
I have also added a couple of video and image extensions as a starter.
Code:
#Updates a file extension, so it can actually play in a media player
#This will have to be perfomed by calling the script manually
#NOTE: IF THERE ARE NO .JPEGs, THE SCRIPT WILL SKIP OVER THEM
#rename - command
#-v - verbose
#s/\ - search for the extension explicitly
#\.xxx$/ - file extension to search for (this is the incorrect extension)
#\.xxxx/ - this is the correct file extension that will replace incorrect extension
#*.xxx - search for all matching (incorrect) file extensions
#rename -v 's/\.htm$/\.html/' *.htm
#rename -v 's/\.htm$/\.html/' *.htm
rename -v 's/\.Mp3$/\.mp3/' *.Mp3
rename -v 's/\.MP3$/\.mp3/' *.MP3
rename -v 's/\.MP4$/\.mp4/' *.MP4
rename -v 's/\.JPG$/\.jpg/' *.JPG
rename -v 's/\.Jpg$/\.jpg/' *.Jpg
rename -v 's/\.AVI$/\.avi/' *.AVI
rename -v 's/\.Avi$/\.avi/' *.Avi
Code:
grab@grabbag:~/scripts$ ./rename.sh
Can't rename *.Mp3 *.mp3: No such file or directory
Can't rename *.MP3 *.mp3: No such file or directory
Can't rename *.MP4 *.mp4: No such file or directory
Can't rename *.JPG *.jpg: No such file or directory
Can't rename *.JPEG *.jpg: No such file or directory
Can't rename *.Jpg *.jpg: No such file or directory
Can't rename *.AVI *.avi: No such file or directory
Can't rename *.Avi *.avi: No such file or directory
Comments (0)