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

NT Batch Equivalent

0 views
Skip to first unread message

SteveeB

unread,
Jun 13, 2001, 9:49:55 PM6/13/01
to
Hello, a few months ago I had someone make me a
batch file for NT that made a file from the
command dir.

The purpose of this batch file was to name the
file the same as the directory name. Example:

Directory name:
c:\mp3's\artists\John Cougar Mellancamp

Batch file:

"assuming this runs in the directory that holds
the mp3's, something like
this ought to work in nt4 and better..."

for /f "tokens=*" %%a in ('cd') do dir *.mp3
/s/b >>"%%~na.m3u"

"or, if you were wanting the script to scan for
mp3's, this might suffice:"

for /r %%b in (.) do (
if exist "%%b\*.mp3" (
pushd "%%b"
for /f "tokens=*" %%a in ('cd') do (
dir *.mp3 /s/b >> "%%~na.m3u"
)
popd
)
)


After running the batch file the file name
produced would be: John Cougar Mellencamp.m3u

Here is what I have in NT format. All I need is to
have it changed so that it will work in DOS in
Win98.

I'm sorry to be butting into this NG and asking
for a DOS batch file but I recently went back to
Win98 from Win2000 for various reasons. If the
person responsible for this batch file reads this,
please convert for me.

P.S. If anyone would like to take a crack at it, I
wouldn't mind and would learn a thing or two while
I'm at it, since I don't know ALL of the cool
commands. Thanks again.

Steve Baker
If you care to email me:
stbak...@hotmail.com

William Allen

unread,
Jun 14, 2001, 2:43:44 AM6/14/01
to
SteveeB wrote in message
...snip

> The purpose of this batch file was to name the
> file the same as the directory name. Example:
>
> Directory name:
> c:\mp3's\artists\John Cougar Mellancamp
...snip

> After running the batch file the file name
> produced would be: John Cougar Mellencamp.m3u

The following is quickly patched together from standard bits and
pieces that are highly general, so it probably looks more complicated
than it is. Handles long folder names with spaces. Not relevant for OS
other than Win9x GUI.

Run in a folder and it creates a dummy file:
WhateverTheFolderNameIs.M3U
and displays DIR info of the file as demo.

::====FOLDER.BAT
@ECHO OFF
IF (%1)==(GOTO:) %1%2 (Subroutine handler)

:: Grab Current FolderName with Universal Prefixer
ECHO.e100'SET RTRIM='>%TEMP%.\UP.BAT
FOR %%F IN (rcx a w q) DO ECHO.%%F>>%TEMP%.\UP.BAT
TYPE %TEMP%.\UP.BAT | debug %TEMP%.\UP.BAT>NUL
CD>>%TEMP%.\UP.BAT
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\UP.BAT

SET DIRNAME=
:LOOP
CALL %0 GOTO: _RTRIM RIGHT
IF (%RIGHT%)==(\) GOTO DONE
SET FOLDER=%RIGHT%%FOLDER%
GOTO LOOP
:DONE

:: Demo code lines
ECHO. Dummy file>"%FOLDER%.M3U"
DIR "%FOLDER%.M3U" | find /i "%FOLDER%.M3U"

:: Clean up
FOR %%V IN (RIGHT RTRIM FOLDER) DO SET %%V=

GOTO EOF (=Subroutine code follows=)
:_RTRIM (Usage: CALL %0 GOTO: _RTRIM RightMostCharVariable)
IF (%3)==() GOTO SUBCALL
ECHO.SET %%1=%RTRIM%xSET %%2=x>%TEMP%.\RT.BAT
ECHO.e90 89 CE 81 C6 F4 0 B8 D A 87 4 83 C6 9 88 4>%TEMP%.\SCR
ECHO.g=90 A0>>%TEMP%.\SCR
FOR %%C IN (w q) DO ECHO.%%C>>%TEMP%.\SCR
TYPE %TEMP%.\SCR | debug %TEMP%.\RT.BAT>NUL
CALL %TEMP%.\RT.BAT RTRIM %3
deltree /y %TEMP%.\RT.BAT %TEMP%.\SCR>NUL

:EOF (End of file)
::====

--
William Allen

PS
1)
Explanation of Universal Prefixer technique in my post:
From: "William Allen"
Newsgroups: alt.msdos.batch
Subject: Line of text from file into environment variable
Date: Tue, 24 Apr 2001 10:40:15 +0100
Message-ID: <9c3hp3$buerc$1...@ID-55970.news.dfncis.de>

You can read old Usenet posts at:
http://groups.google.com/advanced_group_search

Note: Google search by Message-ID is usually the quickest.
Message-ID search works with or without <angle> brackets.
Simply cut-and-paste the Message-ID into Google page above.

2) _RTRIM subroutine applies this simple program to a file
containing environment variable instantiation in order to
split it into its RightMostCharacter and the LeftCharsRemaining.

MOV SI,CX
ADD SI,00F4
MOV AX,0A0D
XCHG AX,[SI]
ADD SI,+09
MOV [SI],AL

Program is encoded directly by script as hex machine code equivalent:
89 CE 81 C6 F4 0 B8 D A 87 4 83 C6 9 88 4


William Allen

unread,
Jun 14, 2001, 3:44:02 AM6/14/01
to
William Allen wrote in message
...snip
> IF (%3)==() GOTO SUBCALL

Sorry, redundant diagnostic template line left in
script by mistake. The above line can be removed.

--
William Allen


Steve Baker

unread,
Jun 14, 2001, 10:47:02 PM6/14/01
to
In article <9g9mfv$83qoc$1...@ID-55970.news.dfncis.de>,
ma...@mayfly13.fsnet.co.uk says...

> ::====FOLDER.BAT
> @ECHO OFF
> IF (%1)==(GOTO:) %1%2 (Subroutine handler)


Thanks William. As you can see, I altered your file slightly to have
it do what I needed. One thing I'd like it to do is exit DOS
automatically. As of now it leaves the DOS window open with no way to
close it other than "X"'ing it out or hitting alt-F4. If you can
instill these changes I'd really appreciate it.

::====FOLDER.BAT
@ECHO OFF
IF (%1)==(GOTO:) %1%2 (Subroutine handler)

:: Grab Current FolderName with Universal Prefixer
ECHO.e100'SET RTRIM='>%TEMP%.\UP.BAT
FOR %%F IN (rcx a w q) DO ECHO.%%F>>%TEMP%.\UP.BAT
TYPE %TEMP%.\UP.BAT | debug %TEMP%.\UP.BAT>NUL
CD>>%TEMP%.\UP.BAT
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\UP.BAT

SET DIRNAME=
:LOOP
CALL %0 GOTO: _RTRIM RIGHT
IF (%RIGHT%)==(\) GOTO DONE
SET FOLDER=%RIGHT%%FOLDER%
GOTO LOOP
:DONE

:: Demo code lines
dir /o:-n /s /b *.mp3>"%FOLDER%.M3U"
DIR "%FOLDER%.M3U" | find /i "%FOLDER%.m3u"

:: Clean up
FOR %%V IN (RIGHT RTRIM FOLDER) DO SET %%V=

GOTO EOF (=Subroutine code follows=)
:_RTRIM (Usage: CALL %0 GOTO: _RTRIM RightMostCharVariable)
IF (%3)==() GOTO SUBCALL
ECHO.SET %%1=%RTRIM%xSET %%2=x>%TEMP%.\RT.BAT
ECHO.e90 89 CE 81 C6 F4 0 B8 D A 87 4 83 C6 9 88 4>%TEMP%.\SCR
ECHO.g=90 A0>>%TEMP%.\SCR
FOR %%C IN (w q) DO ECHO.%%C>>%TEMP%.\SCR
TYPE %TEMP%.\SCR | debug %TEMP%.\RT.BAT>NUL
CALL %TEMP%.\RT.BAT RTRIM %3
deltree /y %TEMP%.\RT.BAT %TEMP%.\SCR>NUL

:EOF (End of file)

Thanks again.

Steve Baker

William Allen

unread,
Jun 15, 2001, 2:12:52 AM6/15/01
to
Steve Baker wrote in message

> One thing I'd like it to do is exit DOS automatically.

::===========Alter current script to add CLS/EXIT at _this_point_:


:: Clean up
FOR %%V IN (RIGHT RTRIM FOLDER) DO SET %%V=

CLS
EXIT

GOTO EOF (=Subroutine code follows=)

::===========

(This point is the end of the logical flow).

Note:
1)
The line:


DIR "%FOLDER%.M3U" | find /i "%FOLDER%.m3u"

is redundant.
2)
The line:
IF (%3)==() GOTO SUBCALL
is one I left in by accident (it's part of diagnostic template)
and can be removed without effect.

--
William Allen


Steve Baker

unread,
Jun 15, 2001, 8:10:48 AM6/15/01
to
In article <9gcc0c$8b36t$2...@ID-55970.news.dfncis.de>,
ma...@mayfly13.fsnet.co.uk says...
Thanks again.

Steve Baker

0 new messages