LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2007, 01:27 PM   #1
aidansmoker
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Rep: Reputation: 0
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
 
Old 11-08-2007, 03:38 PM   #2
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,813

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by aidansmoker View Post
wanted to convert about 10 thousand files in .wma to .mp3 and found a script to do it which is shown below.
Assuming your script is called "wmaconv", what about:
Code:
find top-level-dir -type d | while read DIRNAME
do
   cd $DIRNAME
   wmaconv
done
If you modified your script so that it would accept the directory name as a command line argument and did the "cd" for you, you could then do the above as a one-liner:
Code:
find top-level-dir -type d -exec wmaconf {} \;
Hope this helps a bit.

--
RT
 
Old 11-09-2007, 11:28 AM   #3
aidansmoker
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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

Last edited by aidansmoker; 11-09-2007 at 11:32 AM. Reason: add eample of error
 
Old 11-11-2007, 10:43 PM   #4
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,813

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by aidansmoker View Post
... how do I modify your code to deal with spaces in the folder names; the code seems to be having problems with that?
OK... If you're referring to the "while-do" example, I'm guessing that the "cd $DIRNAME" line is where the error lies, right? Try changing that line to read:
Code:
cd "$DIRNAME"
Single quotes should not be used because the shell substitution would break. If you're trying to get into one of these directories from the CLI, you can precede each space by a backslash ("\") or enclose the space-laden directory/file name in quotes:
Code:
cd Djam\ Karet
cd "Djam Karet"
cd 'Djam Karet'
would all work.
Single or double quotes will work in this case so long as you aren't referencing a shell variable:
Code:
cd '$GENRE/Djam Karet'
would not work (see the first code snippet's warning). Double quotes would be needed in the above example.

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? )
 
Old 11-11-2007, 11:39 PM   #5
aidansmoker
LQ Newbie
 
Registered: Nov 2007
Posts: 4

Original Poster
Rep: Reputation: 0
Smile

Thats it alright, thanks RT. I agree, I prefer to stick to no spaces or capitals, it's just all round easier.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to compare numbers inside two text files bugg_deccan Programming 3 10-17-2007 09:53 PM
Deleting files/folders in Ubuntu 7.04 gwynn Linux - Newbie 5 06-07-2007 01:21 PM
shell script to recursively "compare" all files in a directory... silex_88 Programming 3 05-12-2007 04:24 AM
How to unzip files recursively inside folders? jessdog9001 Linux - Software 2 03-22-2006 12:59 PM
Delete old files and folders Script? AsteX Linux - General 4 11-11-2004 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration