VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: SOLVED - Help wanted on scripting problem with spaces in filenames  (Read 3070 times)

Joe1962

  • Administrator
  • Vectorian
  • *****
  • Posts: 2499
    • Joe1962's Website

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

Code: [Select]
#!/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, 10: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
Re: Help wanted on scripting problem with spaces in filenames
« Reply #1 on: May 30, 2009, 06:13:46 am »

this should do it
Code: [Select]
#!/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
    • Joe1962's Website
Re: Help wanted on scripting problem with spaces in filenames
« Reply #2 on: June 02, 2009, 07: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: [Select]
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: [Select]
lame --preset standard '"'$I'"' '"'${I%.wav}".mp3"'"'
Any ideas?    ???
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
Re: Help wanted on scripting problem with spaces in filenames
« Reply #3 on: June 02, 2009, 05:50:48 pm »

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

Code: [Select]
#!/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
    • Joe1962's Website
Re: Help wanted on scripting problem with spaces in filenames
« Reply #4 on: June 05, 2009, 08:29:18 am »

Cool! This works, thanks... :)
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