Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

concatenate two string variables??

4,054 views
Skip to first unread message

George

unread,
Jan 8, 2003, 11:41:24 AM1/8/03
to
I have an NT5 batch file that is called by EAC www.exactaudiocopy.de
using external compressor
C:\WINNT\system32\CMD.EXE
to fool it into running a batch file with options
/c c:\rmd5.bat %s,%d,"%a","%g","%t","%n"
where
:: %s -> %1 Source Filename
:: %d -> %2 Destination Filename
:: %a -> %3 CD Artist
:: %g -> %4 CD Title
:: %t -> %5 Track Title
:: %n -> %6 Track Number
and I'm trying to store some of the information passed to the bat file
in a text file for later use.

The nub is this requires me to concatenate two strings that may contain
spaces and get rid of the quotation marks..

At the moment I get

""John Williams" - "Pricess Leia's Theme".wav","John Williams","The Star
Wars Trilogy","Pricess Leia's Theme","3"
using
echo "%3 - %5.wav",%3,%4,%5,%6 >>%4.txt
however I'd like to get
"John Williams - Pricess Leia's Theme.wav"
as the first value, notice the file name only has quotes around it not
in it.

Thanks in advance

George

Al Dunbar

unread,
Jan 8, 2003, 11:44:13 AM1/8/03
to

"George" <vstunte...@removeyahoo.com> wrote in message
news:3E1C54B4...@removeyahoo.com...

In 2k and XP, this will work:

echo "%~3 - %~5.wav",%3,%4,%5,%6 >>%4.txt

I don't remember if this works in NT, but, if not, the following will work
in NT 2k and XP:

set par3=%3
set par3=%par3:"=%
set par5=%5
set par5=%par5:"=%
echo "%par3% - %par5%.wav",%3,%4,%5,%6 >>%4.txt

/Al


George

unread,
Jan 11, 2003, 9:58:34 AM1/11/03
to
Al thank you for your response that works well.

Can you think of a page somewhere on the net with a listing of all the
possible variable manipulation operators.

The next hard bit of my task is going to be when I want to retrieve the info
from the text file and put it in the ID3 tag of an MP3 using LAME
http://www.mp3dev.org/ any tips gratefully accepted.

Also is it possible to have wide cards in a string compare if statement like

IF %3 EQU "*ariou*" set Fname="[%~6] %~5.Twav" ELSE set Fname="%~3 [%~6]
%~5.Fwav"
this doesn't work but I'd like to fix it so as to get rid of CD Artist if
it's various artist
Thank you again
George

Clay Calvert

unread,
Jan 11, 2003, 11:40:20 AM1/11/03
to
On Sat, 11 Jan 2003 14:58:34 +0000, George
<vstunte...@removeyahoo.com> wrote:

>Al thank you for your response that works well.
>
>Can you think of a page somewhere on the net with a listing of all the
>possible variable manipulation operators.


This used to be on the 'net, but I can't find it right now. I can't
swear if this is all of them, but I think it is.

The following are examples of variable substitution and parsing in
Windows NT and Windows 2000.
A "#" character will indicate functionality only available in Windows
2000, and most likely XP.

More information can be found from running "Set /?" and "For /?".

A "one-sided" variable is a single character variable that has a
single percent sign preceding the character. Examples: %1 and %a


"Two-sided" variables can have more than one character and have a
percentage sign on both sides.
Examples: %temp% and %path%

The following string will be used for these examples:

set test=123456789abcdef0

Substitution [: and =] Two sided only

%PATH:str1=str2%
%PATH:str1=%
%PATH:*str1=str2%

%Test:ab=xy% 123456789xycdef0
%Test:ab=% 123456789cdef0
%Test:*ab=% cdef0
%Test:*ab=XY% XYcdef0


Parsing [%:~X% and %:~X,Y%] Two sided variables only

Extract only the first 5 characters
%test:~0,5%
12345

Skip 7 characters and then extract the next 5
%test:~7,5%
89abc

Skip 7 characters and then extract everything else
%test:~7%
89abcdef0

Extract only the last 7 characters #
%test:~-7%
abcdef0

Extract everything BUT the last 7 characters #
%test:~0,-7%
123456789

Extract between 7 from the front and 5 from the back #
%test:~7,-5%
89ab

Go back 7 from the end then extract 5 towards the end #
%test:~-7,5%
abcde

Extract between 7 from the end and 5 from the end #
%test:~-7,-5%
ab


[%~letter] One sided variables only

%~I removes any surrounding quotes (")
%~fI Fully qualified path name
%~dI Drive letter only
%~pI Path only
%~nI file Name only
%~xI eXtension only
%~sI Short names only
%~aI Attributes #
%~tI Time and date of file #
%~zI siZe of file #

[%~$string] Two-sided
%~$PATH:I searches the PATH and expands to the full name of the
first found

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:i - searches the PATH and expands to the drive letter and
path of the first found
%~ftzaI - expands %I to a DIR like output line #

In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.


Clay Calvert
CCal...@Wanguru.com
Replace "W" with "L"

Al Dunbar

unread,
Jan 11, 2003, 12:28:48 PM1/11/03
to

"Clay Calvert" <ccal...@Wanguru.com> wrote in message
news:c7d02vo2br8vmqtca...@4ax.com...

> On Sat, 11 Jan 2003 14:58:34 +0000, George
> <vstunte...@removeyahoo.com> wrote:
>
> >Al thank you for your response that works well.

You are welcome.

> >Can you think of a page somewhere on the net with a listing of all the
> >possible variable manipulation operators.

I can't either, but neither can I easily outdo the information that Clay
provided.

/Al

Clay Calvert

unread,
Jan 11, 2003, 2:18:44 PM1/11/03
to
On Sat, 11 Jan 2003 17:28:48 GMT, "Al Dunbar"
<Luigi...@hotmail.com> wrote:

>> >Can you think of a page somewhere on the net with a listing of all the
>> >possible variable manipulation operators.
>
>I can't either, but neither can I easily outdo the information that Clay
>provided.
>
>/Al

That's an honor coming from you, Al.

Here is a place on the 'net for this information, but it is cheating a
little. : )

groups.google.com/groups?&selm=b5tm8ug8kkvf6krj9jtih8s195gcr85ekt%404ax.com

The above will probably wrap.

Thanks,
Clay

George

unread,
Jan 14, 2003, 5:55:15 AM1/14/03
to
Wow I'll keep that.

The last time I did any batch programming was to write a rather complicated
DOS 5.22 boot menu in Autoexec.bat for my Farther to give him the option to
either run windows 3.1, suppercalc his dos based spreadsheet, auto backup
his all work onto floppys using Pkzip, run scandisk followed by defrag or
drop to Dos.

I was enormously proud and considering I was 13 and we had no Internet
connection so I had to work it all out using "help" I think justifiably. The
next time I picked up a keyboard Windows 95 had been born and we were in a
brave new world of the GUI operating system witch was supposed to not be
built on a DOS foundation. Of coarse it was built on DOS (albeit a crippled
version) and that was its saving grace.

I jumped to the NT world in 98 when I discovered my 95 cd key worked on the
NT4 disks we had thrown out at work (they retaining a couple of disks and
all the licenses of course). Now I'm on the steep bit of the learning curve
with Linux although this project is for NT5 (Win2K) and I'm just trying to
write a load of batch to enable me to backup all my and my girlfriends Cds
to shns.

SHN or shorten is a non lossy compression algorithm reducing files to about
%50 the size of the original WAV for long term archiving. Goto www.etree.org

Progress so far, here is the batch file called by EAC at the end of each wav
file extraction (just tell EAC to use an external sound file compressor
C:\WINNT\system32\CMD.EXE passing
/c c:\rmd5.cmd %s,%d,"%a","%g","%t","%n"). EAC for me drops the files into
D:\WAVS\Artist\CDTitle\
The bat file checks if a text file CD Title WAV.md5 exists. If it doesn't
create one, md5sum the newly created WAV file and add the check sum to the
text file in the format {sum} *filename.wav.
If the .md5 file exists add the check sum to a new line in the .md5 file.
Since SHN is non lossy if you decompress one back to a WAV the checksum is
the same as it was before compression.

It also stores filename, CD Artist, CD Title, Track Title, Track Number in a
file called CD Title.txt for putting in the ID3 tag of mp3s later.

@echo off
:: pass from EAC in this order


:: %s -> %1 Source Filename
:: %d -> %2 Destination Filename
:: %a -> %3 CD Artist
:: %g -> %4 CD Title
:: %t -> %5 Track Title
:: %n -> %6 Track Number

:: exclude various artists from file name.
echo %3 | findstr /I ".ariou." >NUL
if errorlevel 1 (
echo arious not contained in %~3
set Fname="%~3 [%~6] %~5.wav"
goto:EndIf
)
echo arious is contained in %~3
set Fname="[%~6] %~5.wav"
goto:EndIf
:EndIf
:: echo %Fname% >> a.txt
:: goto the corect drive and directory
%~d1
cd\
cd %~p1
:: rename the WAV created by EAC
ren %~nx1 %Fname%
:: store the future ID3 tag info
echo %Fname%,%3,%4,%5,%6 >>%4.txt
:: store the WAV md5summs
md5sum %Fname% >>"%~4 WAV.md5"
:: give EAC something to delete
copy %4.txt %~nx1
:: Delete it anyway as EAC doesn't
del %~nx1 /q
::Don't think this works but it doesn't matter.
set %errorlevel% = 0
::pause
exit

Next I need to write a batch file that i can run after ripping 4 or 5 cds to
wav files to shn them. Eac drops the files into a directory in the format
?:/wavs/artist/cd title/artist – songname.wav. I have a dedicated removable
harddrive for shn, I'd like the bat file to MD5 sum the WAV file and if OK
create the shn directly to ?:/shns/artist/cd title/artist – songname.shn. It
will then copy across the ?:/wavs/artist/cd title/[cdtitle] WAV.md5 and .txt
files (if it hasn't been done all ready) and put the md5sum of the new SHN
file into a file ?:/shns/artist/cd title/[cdtitle] SHN.md5 then delete the
old WAV file before moving on to the next one.

Then I need to repeat that process for SHN to MP3 (with mp3s going to
?:/MP3/..., I use SHN for archiving and MP3 for listening. I hope soon to
buy one of the Creative Labs MP3 players with a 20Gig laptop harddrive in.
The SHN to MP3 will md5 the SHN, if OK convert the SHN to a WAV, MD5sum the
WAV and if it's OK create the MP3 directly to ?:/mp3/artist/cd title/artist
– songname.mp3 Using LAME http://www.mp3dev.org/mp3/ getting the ID3 Tag
info from the CDTitle.txt file.
Then it'll do md5sum for the MP3 and put it in ?:/mp3/artist/cd
title/cdtitle MP3.md5. Then Ill add the new filename to a file called
?:/mp3/cdtitle.m3u (a playlist) in the format /artist/cd title/artist –
songname.mp3 (fortunately file locations only have to be relative).

The only files I'm going to store in the MP3 directory is an MD5 file per
album for the MP3s and the M3U playlists.

After that I'll write another batch file that will step threw either the
?:/mp3/ or shn directory checking the md5summs and putting the filename and
location of any that fail into a file called Corrupt_music.txt in my C:\.

That's it.

Sorry for the long post but I think these will be 4 very useful batch files
for any computer audio user. And the beauty of it all is it only requires
the installation of 1 GUI application, EAC which all power to Andre Wiethof
is the mutts nuts though I'm sad no Linux port is planed
www.exactaudiocopy.de. Also you need 3 command line utilities md5sum.exe and
shorten32.exe both available from www.etree.org and Lame.exe
http://www.mp3dev.org/mp3/ .

Some people (my family) have commented that I'm being a bit over zealous
with the md5sums however I'm fed up with pops and clicks appearing in my
soundfiles, I know some of the batch files will take a long time to complete
and suspect they'll be overnight tasks but a lot of the best tasks are;-)

I'll keep this group posted on my progress and I dare say I'll be asking
more questions later.

Thank you to Al Dunbar and Clay Calvert for your help so far.

George

Musafir

unread,
Jan 14, 2003, 12:27:39 PM1/14/03
to
Since this is a personal use project (read 'you have full control of
the environment') and it involves text and regex processing, you might
want to consider writing it in Perl (additionally, this way, when your
vendor goes to Linux, you still have working scripts!).

Evidently you are making healthy progress and might be averse to a
re-write. But, over time, you will want to make enhancements that
might push NT Shell Scripting to it's limits. On the flip side, I am
yet to see a real world problem posed here and not getting a
satisfactory solution/work-around.

Just a few thoughts. Good luck and warm regards,
Sharad Agarwal

Al Dunbar

unread,
Jan 14, 2003, 7:55:20 PM1/14/03
to

"George" <vstunte...@removeyahoo.com> wrote in message
news:3E23EC93...@removeyahoo.com...

> Wow I'll keep that.

<snip>

> It also stores filename, CD Artist, CD Title, Track Title, Track Number in
a
> file called CD Title.txt for putting in the ID3 tag of mp3s later.
>
> @echo off
> :: pass from EAC in this order
> :: %s -> %1 Source Filename
> :: %d -> %2 Destination Filename
> :: %a -> %3 CD Artist
> :: %g -> %4 CD Title
> :: %t -> %5 Track Title
> :: %n -> %6 Track Number
> :: exclude various artists from file name.
> echo %3 | findstr /I ".ariou." >NUL

I would suggest changing this:

> if errorlevel 1 (
> echo arious not contained in %~3
> set Fname="%~3 [%~6] %~5.wav"
> goto:EndIf
> )
> echo arious is contained in %~3
> set Fname="[%~6] %~5.wav"
> goto:EndIf
> :EndIf

to this:

> if errorlevel 1 (
> echo arious not contained in %~3
> set Fname="%~3 [%~6] %~5.wav"

> ) else (


> echo arious is contained in %~3
> set Fname="[%~6] %~5.wav"

> )

This avoids the messy GOTO's and the :Endif label altogether.

<snip>

> I'll keep this group posted on my progress and I dare say I'll be asking
> more questions later.
>
> Thank you to Al Dunbar and Clay Calvert for your help so far.

You are most welcome.

/Al


0 new messages