Batch File to manipulate path and file name

G

Guest

I'm trying to use a batch file to convert some .wav files to .mp3 files using
a program called switch. All of my .wav files are stored in a directory on
my network. The files are of the type h:\music\artist name\cd name\song.wav.
I want to convert all of these files to .mp3 files and store them in another
subdirectory. The files should be stored in h:\mp3\artist name\cd
name\song.mp3. I know I can use the for /R command to recursively go through
the h:\music subdirectory. My question is this. I need to pass the
h:\mp3\artist name\cd name portion of the path to switch to tell it where to
store the output files. How can I manipulate the path of the .wav file to
eliminate the music part of the path and replace it with mp3 and then remove
the song name from that path since switch assumes that the song name will be
the same with the .mp3 extension on it? The other question that I've got is
can I do this manipulation in a batch file before the for /R command so that
I've got a variable that is of the form h:\mp3\artist name\cd name and just
pass that variable to switch so that it can use that variable to tell it
where to store the output. Any help that can be offered will be greatly
appreciated.
 
P

Pegasus \(MVP\)

ebferro said:
I'm trying to use a batch file to convert some .wav files to .mp3 files
using
a program called switch. All of my .wav files are stored in a directory
on
my network. The files are of the type h:\music\artist name\cd
name\song.wav.
I want to convert all of these files to .mp3 files and store them in
another
subdirectory. The files should be stored in h:\mp3\artist name\cd
name\song.mp3. I know I can use the for /R command to recursively go
through
the h:\music subdirectory. My question is this. I need to pass the
h:\mp3\artist name\cd name portion of the path to switch to tell it where
to
store the output files. How can I manipulate the path of the .wav file to
eliminate the music part of the path and replace it with mp3 and then
remove
the song name from that path since switch assumes that the song name will
be
the same with the .mp3 extension on it? The other question that I've got
is
can I do this manipulation in a batch file before the for /R command so
that
I've got a variable that is of the form h:\mp3\artist name\cd name and
just
pass that variable to switch so that it can use that variable to tell it
where to store the output. Any help that can be offered will be greatly
appreciated.

I think I know what I want to do and I'm sure that it can be done.
However, after reading your note three times I'm still not sure that
I understand your exact aim. An example for each of the two
parts of your question would make things a lot clearer.
 
E

ebferro

Pegasus:
The short form is this:
Input File Name: h:\music\artist name\cd name\song name.wav
Output File Name Desired h:\mp3\artist name\cd name

How do I get from Input File Name to Output File Name Desired? I realize
that there is no song name.mp3 on the output file name desired. Switch, the
program that I'm using takes care of that on its own.

Second question summarizes to in a batch file, can I create a variable with
the input file name in it and massage that variable somehow to get the output
file name desired and then use that variable in a for /R loop to run through
all of the songs in my h:\music subdirectory to conver them? And, if I can,
how do I do that?
Thanks in advance.
 
P

Pegasus \(MVP\)

This batch file should get you started. You must remove the # chars
I used to mark the beginning of each line.

#@echo off
#set Source=d:\My Music
#for /F "delims=" %%a in ('dir /b /s "%Source%\*.wav"') do call :Sub %%a
#goto :eof
#
#:Sub
#for %%b in ("%*") do (
#echo Full name=%*
#echo Path=%%~pb
#echo File Name=%%~nb
#echo Ext=%%~xb
#)

Feel free to ask if you need an explanation of the code.
 
E

ebferro

Pegasus:
Thanks for your help. I think I understand the code and we're getting
closer. I've run the batch file that you provided and it went through one cd
and started the second one. I got an error that says .wav was unexpected at
this time. The next song to be displayed has parentheses in its name. Could
that be the problem? There are a number of song names that have characters
like &, (, ), etc in them. Is there any way to accomodate these characters
if that's the problem?
Thanks again.
 
P

Pegasus \(MVP\)

Yes, parentheses belong to the so-called "poison" characters
in batch files. I'll have to think about this one.
 
P

Pegasus \(MVP\)

I recommend you try your luck in alt.msdos.batch.nt. They
love to dig their teeth into this sort of thing. Remember to
state the OS you use.
 
P

Pegasus \(MVP\)

If you don't mind a mixed solution then you could use this batch
file as a starting point. It should process any "poison" characters
in the file names correctly.
#@echo off
#set delimiter=*
#set Source=My Music
#set TempFile=%temp%\files.txt
#
#dir /b /s "%Source%\*.wav" | cscript //nologo d:\temp\test.vbs %delimiter%
"%TempFile%"
#for /F "tokens=1-4 usebackq delims=%delimiter%" %%a in ("%TempFile%") do (
# echo Full name=%%a
# echo Path=%%b
# echo Name=%%c
# echo Extension=%%d
#)

You must select a suitable delimiter, i.e. a character that will not
occur in any of your file names. I used an asterisk (*) since asterisks
are not allowed in file names.

And here is the VB Script test.vbs that goes with it:
#Set fso=CreateObject ("Scripting.FileSystemObject")
#Set stdin = fso.GetStandardStream (0)
#Set objArgs = WScript.Arguments
#
#delim = "*"
#If objArgs.Count > 0 Then delim = Left(objArgs(0), 1)
#
#Do
# line = stdin.ReadLine
# p = InStrRev(line, "\")
# q = InStrRev(line, ".")
# WScript.Echo line & delim & Left(line, p) & delim & Mid(line, p+1, q-p-1)
& delim & Right(line, 4)
#Loop Until stdin.AtEndOfStream

If you object to requiring two files to achieve your aim (one batch,
one VBS) then you could generate the .vbs file from within the
batch file with a number of suitable "echo" statements.
 
B

Bob I

Just rename "Music" folder to "MP3", done deal.
Pegasus:
The short form is this:
Input File Name: h:\music\artist name\cd name\song name.wav
Output File Name Desired h:\mp3\artist name\cd name

How do I get from Input File Name to Output File Name Desired? I realize
that there is no song name.mp3 on the output file name desired. Switch, the
program that I'm using takes care of that on its own.

Second question summarizes to in a batch file, can I create a variable with
the input file name in it and massage that variable somehow to get the output
file name desired and then use that variable in a for /R loop to run through
all of the songs in my h:\music subdirectory to conver them? And, if I can,
how do I do that?
Thanks in advance.



:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top