Entering folders recursively to run script on files nested inside, ubuntu 7.10
Hi,
I'm pretty new to Linux but have some grasp of basics. I wanted to convert about 10 thousand files in .wma to .mp3 and found a script to do it which is shown below. Problem is it will only convert the files in one folder. How can I get it to operate recursively on a series of nested folders so that it enters thm automatically and I don't have to cd into each one and run by hand? Thanks in advance Script: courtesy user from melbourne, aus., username=cajd ********************************************************* #!/bin/bash current_directory=$( pwd ) #remove spaces for i in *.wma; do mv "$i" `echo $i | tr ' ' '_'`; done #remove uppercase for i in *.[Ww][Mm][Aa]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done #Rip with Mplayer / encode with LAME for i in *.wma ; do mplayer -vo null -vc dummy -af resample=44100 -ao pcm -waveheader $i && lame -m s audiodump.wav -o "`basename "$i" .wma`.mp3"; done #convert file names for i in *.wma; do mv "$i" "`basename "$i" .wma`.mp3"; done rm audiodump.wav |
Quote:
Code:
find top-level-dir -type d | while read DIRNAME Code:
find top-level-dir -type d -exec wmaconf {} \; -- RT |
Spaces
Thanks RT
One last problem though, how do I modify your code to deal with spaces in the folder names; the code seems to be having problems with that? It gives me "Music/The: no such file or dir." error for folder 'The X'. Aidan |
Quote:
Code:
cd "$DIRNAME" Code:
cd Djam\ Karet Single or double quotes will work in this case so long as you aren't referencing a shell variable: Code:
cd '$GENRE/Djam Karet' Boy! What I'd give for five minutes in a dark alley with a baseball bat and the bozo who thought spaces in directory and file names was a cool idea. I probably get at least one question a week at work about this. It's gotten to be second nature for me when saving files sent to me -- almost always from a Windows user but from the occasional Mac user as well -- that I automatically change all the spaces to underscores. Making that little fix once saves me so much trouble later on. Fixing them -- or just dealing with them -- after the fact is a pain. As you're finding out. Unfortunately, I seem to recall some ripping software that seemed to want to embed spaces in sound filenames. Guess that's why I wound up sticking with cdrecord and homegrown scripts. (And guess what my scripts do with any spaces in album/song titles? :) ) |
Thats it alright, thanks RT. I agree, I prefer to stick to no spaces or capitals, it's just all round easier.
|
All times are GMT -5. The time now is 03:33 PM. |