Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MorphingDragon

macrumors 603
Original poster
Mar 27, 2009
5,159
6
The World Inbetween
I need to rename some 1000+ sound files that were incorrectly ripped as .mp4 instead of .m4a. iTunes 10 and my iPod tries to play them as video files and its very annoying.

I tried using BASH and SED but that didn't work too well and scripts online needed a text file of all the files and the renames.

What I want -> A script that goes through a folder and its sub folders and rename any *.mp4 files to *.m4a
 
I need to rename some 1000+ sound files that were incorrectly ripped as .mp4 instead of .m4a. iTunes 10 and my iPod tries to play them as video files and its very annoying.

I tried using BASH and SED but that didn't work too well and scripts online needed a text file of all the files and the renames.

What I want -> A script that goes through a folder and its sub folders and rename any *.mp4 files to *.m4a

Try this simple script in the console:

for f in *.mp4; do echo $f; done

Then modify it as needed. Renaming is done by using "mv".
 
Try this simple script in the console:

for f in *.mp4; do echo $f; done

Then modify it as needed. Renaming is done by using "mv".

I get
Code:
*.mp4
as my output, as it doesn't read into the sub folders. It works in individual folders with the songs.

I'm surprised my RedHat training didn't cover something like this.
 
I get
Code:
*.mp4
as my output, as it doesn't read into the sub folders. It works in individual folders with the songs.

I'm surprised my RedHat training didn't cover something like this.

You might use */*.mp4 if all the files are one level deep. Otherwise, a 'find' command something like:
Code:
find /path/of/base/dir -name '*.mp4' -exec mv ..other stuff here.. \;
See the man page for find.

I think Automator is better in this case, though, unless you're starting with a tested 'find' command-line.
 
Get Ruby to do the heavy lifting for you:

Code:
find  . -iname \*mp4 | ruby -ne 'puts "mv \"#{$_.chomp}\" \"#{$_.chomp.sub(/mp4$/, "m4a")}\""'

Run that command in the root directory where the files are located. It should generate a series of mv commands that will do what you want. If you're happy with it, execute it by piping it to bash (you can use !! as a shortcut for the previous command):

Code:
!! | bash
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.