Re: Batch File to manipulate path and file name

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.


"ebferro" <ebferro@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5DE24978-686F-4B1E-8E85-1FC3CC05569F@xxxxxxxxxxxxxxxx
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.

"Pegasus (MVP)" wrote:

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.


"ebferro" <ebferro@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6ECA3417-4706-438B-83EF-E25A0DCD2E94@xxxxxxxxxxxxxxxx
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.



"Pegasus (MVP)" wrote:


"ebferro" <ebferro@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:104B0630-6314-4D1A-8E1E-63AD63BE9ED8@xxxxxxxxxxxxxxxx
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.








.



Relevant Pages

  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: File Size Check
    ... the batch ended and was done. ... del para2.txt ... echo open ... SLEEP is part of the WinNT/2K/XP/2003 Resource Kit and not a ...
    (microsoft.public.scripting.vbscript)
  • Re: del not working in .bat file
    ... Haven't managed yet to do away with the .bat file and run this: ... Try using the CALL command inside the batch file. ... @echo off ... executes, which calls test2.bat and that executes. ...
    (microsoft.public.vb.general.discussion)
  • Re: del not working in .bat file
    ... Try using the CALL command inside the batch file. ... @echo off ... executes, which calls test2.bat and that executes. ...
    (microsoft.public.vb.general.discussion)
  • Re: [opensuse] Colorized output, echo via xargs.
    ... Here you're invoking the shell's built-in echo command, ... You can explicitly turn off the interpretation of the above ... characters with the -E option. ... -e enable interpretation of backslash escapes ...
    (SuSE)