VectorLinux
July 30, 2014, 02:53:05 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: SOLVED - Help wanted on scripting problem with spaces in filenames  (Read 2536 times)
Joe1962
Administrator
Vectorian
*****
Posts: 2499



WWW
« on: May 29, 2009, 01:22:29 pm »

So I use this little script to convert a directory of wav files to mp3:

Code:
#!/bin/sh
#
# This is wav2lame-batch
# run it on a directory of wav files
# to batch convert them to mp3.
#
WAVS=$(ls -1 *.wav)

for I in $WAVS; do
#lame --preset 128 $I ${I%.wav}".mp3"
lame --preset standard $I ${I%.wav}".mp3"
done

This works except when it comes up against a filename with spaces. I've tried a few variations after checking some bash docs, but can't get it to work. Any help would be appreciated...
« Last Edit: June 08, 2009, 09:47:36 am by Joe1962 » Logged

O'Neill (RE the Asgard): "Usually they ask nicely before they ignore us and do what they damn well please."
http://joe1962.bigbox.info
Running: VL 7 Std 64 + self-cooked XFCE-4.10
uelsk8s
Administrator
Vectorian
*****
Posts: 2504



« Reply #1 on: May 30, 2009, 05:13:46 am »

this should do it
Code:
#!/bin/sh
#
# This is wav2lame-batch
# run it on a directory of wav files
# to batch convert them to mp3.
#

ls -1 *.wav|while read I;do
#lame --preset 128 $I ${I%.wav}".mp3"
#lame --preset standard $I ${I%.wav}".mp3"
        echo $I
done
Logged
Joe1962
Administrator
Vectorian
*****
Posts: 2499



WWW
« Reply #2 on: June 02, 2009, 06:16:55 am »

This is a step in the right direction, but lame can't handle it like that, but rather needs it like this:
Quote
lame --preset standard "03 - Director's commentary.wav" "03 - Director's commentary.mp3"
A little experimenting got me this:
Code:
echo '"'$I'"' '"'${I%.wav}".mp3"'"'
Which gives this, for example:
Quote
"03 - Director's commentary.wav" "03 - Director's commentary.mp3"
However, the following just will not work:
Code:
lame --preset standard '"'$I'"' '"'${I%.wav}".mp3"'"'

Any ideas?    Huh
Logged

O'Neill (RE the Asgard): "Usually they ask nicely before they ignore us and do what they damn well please."
http://joe1962.bigbox.info
Running: VL 7 Std 64 + self-cooked XFCE-4.10
Jason W
Member
*
Posts: 2


« Reply #3 on: June 02, 2009, 04:50:48 pm »

A small tweak to the script works here, maybe worth a try:

Code:
#!/bin/sh
#
# This is wav2lame-batch
# run it on a directory of wav files
# to batch convert them to mp3.
#

ls *.wav|while read I;do
#lame --preset 128 $I ${I%.wav}".mp3"
lame --preset standard "$I" "${I%.wav}.mp3"
        echo "${I%.wav}.mp3"
done
Logged
Joe1962
Administrator
Vectorian
*****
Posts: 2499



WWW
« Reply #4 on: June 05, 2009, 07:29:18 am »

Cool! This works, thanks... Smiley
Logged

O'Neill (RE the Asgard): "Usually they ask nicely before they ignore us and do what they damn well please."
http://joe1962.bigbox.info
Running: VL 7 Std 64 + self-cooked XFCE-4.10
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!