View Full Version : DOS Batch file. How to rename a file to have the current directory name?


video_magic
13th February 2005, 13:41
Hello. I have made a very simple batchfile, named dirmp3.bat, to create a playlist of all mp3s in the current Folder. The contents of dirmp3.bat so far are:

dir /B /O *.mp3 > ppp.m3u

I then want to rename ppp.m3u to be "name of current folder".m3u
Or preferably output to "name of current folder".m3u in the first place and miss out the renaming step.

I've looked on the internet and have also tried fiddling around with some Dos commands but can't figure out how to do it. I would like a way that is safe for all Windows versions of Dos if possible - i.e. folder names containing spaces, and if there is a way that would also be safe in True MSDos so much the better :)

Thanks if someone can give an example or point to a link

esby
14th February 2005, 12:08
depending if you are on a dos like shell or unix like one (cygwin).
* dos
'cd' without any argument will get you the full directory name

* unix
'pwd' should do the same.

then you'll just add the .m3u extension.

esby

video_magic
16th February 2005, 07:48
Thanks for the reply.

I am using a 'MSDos command prompt window' in Windows XP.

CD does displays the full path - not just the current directory name, and also, within my batch file I still don't know how to get the current directory name as being the name of my file before the extension.

Example of what I am trying to do. I want to copy my batch file into a directory that contains some mp3s.
Then I would like to click on the batch file and it creates an mp3 play-list (.m3u) in the directory of the mp3s in that directory.
So far - no problem!, the batch file as in my first post creates that mp3 play-list just fine and gives it the name 'ppp.m3u'

What I would like to do is have the created .m3u file have the name of the directory which it was created in.

So if I have a directory c:\foomusic\mjtunes\
and there are some mp3s in it, and I put my bat file in there and run it, then the playlist file that appears in there will be called mjtunes.m3u

esby
16th February 2005, 11:25
just create your file with an absolute path,
and move it to where you might need it.

esby

aquaplaning
16th February 2005, 14:04
the only command where i found filename extraction was inside a "for". it looks a bit confusing, but does what you want.
put this line inside a xxx.bat file:
for /F %%I in ("%CD%") do dir /B /O *.txt > %%~nI.m3u

if you do it that way you can simply drag 'n drop a dir on your batch script. no need to copy anything.
for /F %%I in ("%1") do dir /B /O %1 > %1\%%~nI.m3u

video_magic
16th February 2005, 17:16
Thanks! :)

That helped me solve it, well I actually figured it out to do it as a line like so:

for /F %%I in ("%CD%") do dir /B /O *.mp3 > %%~nI.m3u

Which creates the playlist for all mp3s in a current directory, putting it as 'current-directory-name.m3u' in the directory.

Very cool guys :)

aquaplaning
16th February 2005, 22:18
you'r right!
i tested it on a machine without mp3's, just some text files ...

this would be the correct bat file for drag-n-drop then
for /F %%I in ("%1") do dir /B /O %1\*.mp3 > %1\%%~nI.m3u

video_magic
17th February 2005, 08:19
Cheers Aquaplaning. I'm glad Dos hasn't been killed off because these little things are very nice. Kind of challenging to get into though, I appreciate the pointers :thanks:

iradic
17th February 2005, 08:29
hm, not sure if it will work in DOS...

video_magic
17th February 2005, 22:39
Well... I guess the drag 'n drop version is only for Windows :o

I must get a PC with proper MSDos installed on it, and see if my little normal Batch file will work in that too, I hope it is okay for all Windows versions Dos-modes.
I only have Windows XP and I have been told that it is even less Dos than Dos-Mode, it's only emulated.

I wonder if you guys would do a favour. If you have a different version of Windows than XP, could you run the normal line as a .bat file,

for /F %%I in ("%CD%") do dir /B /O *.mp3 > %%~nI.m3u

in a folder of mp3s and check if it creates the .m3u playlist there with the folder name?

And then post here and say if it worked or not, and say the version of Windows tried on. Thanks.

If someone has real MS-Dos and could try it on that too that would also be great (& say the Dos version).

esby
17th February 2005, 22:48
one other solution could be to make a small executable that do the work...
(and drag&drop would be possible with that too).
I can do one, if you want.

esby

iradic
17th February 2005, 23:26
well /F switch isn't supported in DOS if command...

WinME with MSDOS 6.22

HELP from MSDOS 6.22
FOR

Runs a specified command for each file in a set of files. You can use this
command in batch programs or at the command prompt.

Syntax

To use FOR in a batch program, use the following syntax:

FOR %%variable IN (set) DO command [command-parameters]

To use FOR from the command prompt, use the following syntax:

FOR %variable IN (set) DO command [command-parameters]

Parameters

%%variable or %variable
Represents a replaceable variable. The FOR command replaces %%variable
(or %variable) with each text string in the specified set until the
command (specified in the command parameter) processes all the files.
Use %%variable to carry out the FOR command within a batch program. Use
%variable to carry out FOR from the command prompt.

(set)
Specifies one or more files or text strings that you want to process
with the specified command. The parentheses are required.

command
Specifies the command that you want to carry out on each file included
in the specified set.

command-parameters
Specifies any parameters or switches that you want to use with the
specified command (if the specified command uses any parameters or
switches).

vhelp
18th February 2005, 01:53
Hi guys.

@ esby

Yeah. I agree. That's a great ida (drag-n-drop)
I miss it though. But after a system crash some months ago, I lost
the DCU / componant I used inside my Delphi :(

.
.

FWIW.. I tried your test, and it failed with an error message (below)

The batch script I used was your last one (below) and when run, it
outputed the error message as below:

----- --- ----- --- ----- --- ----- --- ----- --- ----- ---
c:\test\for /F %%I in ("%CD%") do dir /B /O *.mp3 > %%~nI.m3u
Syntax error
----- --- ----- --- ----- --- ----- --- ----- --- ----- ---

OS: Windows 98 Gold

I thought I read somewhere's that you knew another language, DELPHI or VB ??

If so, have you considered esby 's idea of Drag 'n Drop ??

-vhelp

esby
18th February 2005, 02:06
no need for a component for drag & drop in delphi


uses
// snip
shellApi; // [edit] shell api might not be necessary, but you might want to check out the shellExec() and shellExecEx() functions...

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
procedure FormCreate(Sender: TObject);
private
// snip
public
// snip
procedure WMDROPFILES(var Message: TWMDROPFILES); message WM_DROPFILES;
end;


implementation

procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle, True);
end;

procedure TForm1.WMDROPFILES(var Message: TWMDROPFILES);
var
NumFiles : longint;
i : longint;
buffer : array[0..255] of char;
begin
{How many files are being dropped}
NumFiles := DragQueryFile(Message.Drop,
$FFFFFFFF,
nil,
0);
{Accept the dropped files}
// OpenDialog1.Files.Clear; // optional
for i := 0 to (NumFiles-1 ) do begin
DragQueryFile(Message.Drop,
i,
@buffer,
sizeof(buffer));
OpenDialog1.Files.Add(buffer);
end;


esby

video_magic
18th February 2005, 10:41
Originally posted by esby
one other solution could be to make a small executable that do the work...
(and drag&drop would be possible with that too).
I can do one, if you want.

Thanks, I really appreciate the offer :). Would this exe be standalone & work in MSDos also? I mean that a user would not have to install any extra files to make it work, it would work in a normal installation of Dos 6.x or Windows.

For my purposes I would still also like to have a generic All-Windows, & MSDos 6, working .bat too, but if it's possible - I wonder.
I have been studying a book for MSDos 6.2 but it doesn't have very good explanations. I wonder if the people that write these books remember trying to get into it when they were new :devil:
I've almost given up on looking on the net too unless anyone knows a better search engine than Google

esby
18th February 2005, 13:09
I am not sure about msdos compatibility.

Now there are two different solution:

* command line program. this one should work probably in msdos.
* windows application, even if it is small, i doubt it will work.


The dragndrop i am talking is the one when you drag file to a launched application, so in the first case it will probably not work.
but if you need that I do something, just tell me what you exactly want.
( --> the list of exact features wanted)

esby

iradic
18th February 2005, 20:48
why dont you try tag.exe?

video_magic
19th February 2005, 16:59
Ok thanks esby:

A User puts a little file (like a .bat or maybe .exe or .com) into a directory containing mp3s. They run the little file and it creates an .m3u playlist there of all the mp3s, & the .m3u has the name of the directory in which it was created. The file should not require any other files to be installed before it can be run.

I would like it to work no matter if it's in Windows or MSDOS (version 6 or above).

That's all I want :D; I would definitely like to know the command for a batch file for this if there is one, but I'd appreciate if you can make a different kind, Thanks guys

I am not seeing Drag 'n' Drop as a requirement although it is nice. To run it the user should either just click it in windows, or in MSDOS just go to the directory and type the name of the file to run it (no switches)

esby
20th February 2005, 17:49
you'll have one (or maybe two) application(s) tomorrow.

Now I can answer some of your 'questions'

I doubt it will work in true msdos.
Why?
Because Delphi as far I know can only produce console application, which are meant to work in the window interpreter, but not under (ms)dos.

Now i could use borland pascal to produce an msdos executable...
but the filename length will be a problem, as all filenames would be truncated to 7+3 characters...

Now I am thinking of two applications:
One with the drag capacity, a classic windowed one, which should work under win98 at least.
And one, console type, which could take the ini created by the first application, and parse all mp3 found in the directory into a m3u file (or something near that).

esby

video_magic
21st February 2005, 13:54
In True MSDos I would not have a problem with short names.
If the user has MSDos then it would just be writing the names that the files and directory already have; But if the same executable was run under Windows I hope it would not truncate filenames then for that would not be an okay solution.

^But if it does short names in MSDos and long names when run under Windows that's fine^

Sounds good esby, Looking forward very much to seeing what you come up with, thanks a lot. I can't program myself so I'm humbled

esby
22nd February 2005, 05:38
here I go:

http://esby.free.Fr/prog/dnd

dnd.exe is the windowed executable
dndc.exe is the console one.

you can modify extension options via dnd.ini file or via -xmp3 -Xm3u command line options (those are examples).

command line option available:
-h for help
-xextension (mp3)
-Xextension (m3u)
-s (saving ini)

-wmyfile.m3u (to write all items to myfile.m3u'
Please note that this last mode cancels auto mode generation.
(eg if you specify two paths, it will generate only ONE m3u file)

Any other argument that does not start by - will be considered as a file or a path to add.


For example:
dndc c:\
will scan the drive c:\ for mp3 files and will create m3u files for each directory that contains mp3 files...

esby

iradic
22nd February 2005, 07:36
hi i took this as a challenge :)

so here it goes (i commented it so i wont explain a lot)
just one thing ... you need to put your code to create m3u playlist...


:: DIRMAGIC.BAT - parse current directory name without path
::
:: # Since the "pure" DOS code is slower check Win version and use
:: the FOR command with /F switch if supported (Win2k/XP)
:: # also writes temp files to disk (it's not that slow)
::
:: IF %OS%==Windows_NT Goto WinNT :: NOT SURE!!!
::
@ECHO off
ECHO.
IF "%1"=="UseMethod2" GOTO Method2
IF "%2"=="Parsing" GOTO Parse

:: ::
:: :: # write temp files to TEMP directory
:: ::
::
:: IF "%TEMP%"=="" SET _ERROR=TEMP variable not set
:: IF NOT EXIST "%TEMP%.\nul" SET _ERROR=TEMP directory not valid
:: IF NOT "%_ERROR%"=="" GOTO Error
::
:: %TEMP%\
:: CD %TEMP%
::
:: :: NOT POSSIBLE???
:: :: (check PROMPT usage and tricks)

::
:: # gat dir name method 1 (long name with spaces)
:: not supported names with "," ";" "=" (MAYBE MORE!!!)

> DIRECTORY.BAT ECHO SET _DIR=%%2
>> DIRECTORY.BAT ECHO SHIFT
>> DIRECTORY.BAT ECHO :Loop
>> DIRECTORY.BAT ECHO IF NOT "%%2"=="" FOR %%%%X IN ( SET SHIFT GOTO:Loop ) DO %%%%X _DIR=%%_DIR%% %%2

> CALLMAIN.BAT DIR %0 | FIND "Directory of " | FIND ":\"
:: output:
:: Directory of DIRECTORY_NAME
:: DIRECTORY.BAT %1 %2

CALL CALLMAIN.BAT

ECHO Directory:
ECHO "%_DIR%"

IF EXIST "%_DIR%.\nul" GOTO Substitute
ECHO Not valid directory name
GOTO SecondRun

:SecondRun
%0 UseMethod2
GOTO End :: TO BE SURE!

::
:: # get dir name method 2 (short file name)
:: using undocumented TRUENAME command
::
:: $ TRUENAME /?
:: Reserved command name

:Method2
ECHO %1

> INVALID.BAT ECHO SET _DIR=%%4

> CALLMAIN.BAT MODE ThisIsTrick .\
>> CALLMAIN.BAT TRUENAME | FIND ":\"
:: output:
:: Invalid parameter - ThisIsTrick DIRECTORY_NAME
:: INVALID.BAT %1 %2 %3 %4
CALL CALLMAIN.BAT

DEL INVALID.BAT

ECHO Directory:
ECHO "%_DIR%"

IF EXIST "%_DIR%.\nul" GOTO Substitute
SET _ERROR=Valid directory name not found
GOTO Error

::
:: # use for easier dir name parsing
::
:: $ SUBST /?
:: Associates a path with a drive letter.
:: SUBST [drive1: [drive2:]path]
:: SUBST drive1: /D
:: drive1: Specifies a virtual drive to which you want to
:: assign a path
:: [drive2:]path Specifies a physical drive and path you want to
:: assign to a virtual drive.
:: /D Deletes a substituted (virtual) drive.
:: Type SUBST with no parameters to display a list of current
:: virtual drives.
::
:: # dropped (maybe if dir is valid input parameter)

:Substitute
GOTO ThirdRun

:ThirdRun
IF "%1"=="UseMethod2" %0 Method2 Parsing %_DIR%
%0 Method1 Parsing %_DIR%
GOTO End

::
:: # parse dir name with CHOICE
::

:Parse
ECHO %1 %2...

:: :: # parse dir test
:: > PARSEDIR.BAT ECHO :Loop
:: >> PARSEDIR.BAT ECHO IF NOT "%%1"=="" FOR %%%%X IN ( ECHO SHIFT GOTO:Loop ) DO %%%%X %%1
::
:: :: # parse dir test output (C:\My Documents):
:: :: ?[ drop
:: :: C drop
:: :: : drop
:: :: \ drop (first run "?[" drop first 4 char)
:: :: M keep
:: :: Y keep
:: :: ]? drop (end)
:: :: ??[ drop (second run "??[")
:: :: D keep with space first
:: :: O keep
:: :: C keep
:: :: U keep # PLUS:
:: :: M keep # on every "\" char reset var
:: :: E keep
:: :: N keep
:: :: T keep
:: :: S keep
:: :: ]? drop

IF "%1"=="Method2" GOTO ParseDir2

:: # FINAL PARSE DIR METHOD 1
::
> PARSEDIR.BAT ECHO IF "%%1"=="?[" GOTO FirstRun
>> PARSEDIR.BAT ECHO GOTO SecondRun
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :FirstRun
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO SET _DIRMAGIC=%%5
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO SHIFT
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO :FirstLoop
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SHIFT
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO IF NOT "%%5"=="]?" FOR %%%%X IN ( SET SHIFT GOTO:FirstLoop ) DO %%%%X _DIRMAGIC=%%_DIRMAGIC%%%%5
>> PARSEDIR.BAT ECHO GOTO End
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :SecondRun
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO SET _DIRMAGIC=%%_DIRMAGIC%% %%2
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO SHIFT
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO :SecondLoop
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SHIFT
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO IF NOT "%%2"=="]?" FOR %%%%X IN ( SET SHIFT GOTO:SecondLoop ) DO %%%%X _DIRMAGIC=%%_DIRMAGIC%%%%2
>> PARSEDIR.BAT ECHO GOTO End
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :End

GOTO ChoiceOut

:ParseDir2
:: # FINAL PARSE DIR METHOD 2 (not adding space on second run)
::
> PARSEDIR.BAT ECHO IF "%%1"=="?[" GOTO FirstRun
>> PARSEDIR.BAT ECHO GOTO SecondRun
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :FirstRun
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO SET _DIRMAGIC=%%5
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO SHIFT
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO :FirstLoop
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SHIFT
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO IF NOT "%%5"=="]?" FOR %%%%X IN ( SET SHIFT GOTO:FirstLoop ) DO %%%%X _DIRMAGIC=%%_DIRMAGIC%%%%5
>> PARSEDIR.BAT ECHO GOTO End
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :SecondRun
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO SET _DIRMAGIC=%%_DIRMAGIC%%%%2
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO SHIFT
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO :SecondLoop
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SET _DIRMAGIC=
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SHIFT
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO IF NOT "%%2"=="]?" FOR %%%%X IN ( SET SHIFT GOTO:SecondLoop ) DO %%%%X _DIRMAGIC=%%_DIRMAGIC%%%%2
>> PARSEDIR.BAT ECHO GOTO End
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :End

:: # FINAL PARSE DIR TEST OUTPUT METHOD 1:
:: for directory:
:: "C:\Program Files\Online Services\MSN50\OCX\valid long name"
:: =================================================================
:: Directory:
:: "C:\Program Files\Online Services\MSN50\OCX\valid long name"
::
:: Method1 Parsing...
:: Parsed directory:
:: "VALID LONG NAME"
:: =================================================================

:: # FINAL PARSE DIR TEST OUTPUT METHOD 2
:: for directory:
:: "C:\Program Files\Online Services\MSN50\OCX\not= valid, long; name"
:: =================================================================
:: Directory:
:: "C:\Program Files\Online Services\MSN50\OCX\not valid long name"
:: Not valid directory name
::
:: UseMethod2
:: Directory:
:: "C:\PROGRA~1\ONLINE~1\MSN50\OCX\NOT_VA~1"
::
:: Method2 Parsing...
:: Parsed directory:
:: "NOT_VA~1"
:: =================================================================

:ChoiceOut

SET _PARSE=%3
> CALLMAIN.BAT ECHO = | CHOICE /C=%3= CALL PARSEDIR.BAT ?
:Loop
SHIFT
>> CALLMAIN.BAT ECHO = | CHOICE /C=%3= CALL PARSEDIR.BAT ??
IF NOT "%4"=="" GOTO Loop
:: output:
:: CALL PARSEDIR.BAT ?[=,D,I,R,E,C,T,O,R,Y,=]?=
:: CALL PARSEDIR.BAT ??[=,N,A,M,E,=]?=
:: CALL PARSEDIR.BAT %1 %2 3 4 5 6 7 8 9 ...

CALL CALLMAIN.BAT

ECHO Parsed directory:
ECHO "%_DIRMAGIC%"

DEL CALLMAIN.BAT
DEL DIRECTORY.BAT
DEL PARSEDIR.BAT

:: # PLACE YOUR BATCH CODE HERE !!!
:: # variables set: _DIR current dir name with path
:: # _DIRMAGIC current dir name without path
::
:: # NOTE: change lines where _DIR var is checked for valid
:: maybe its possible to continue parsing without
:: valid _DIR var (if you do not need !!! EXACT !!! dir name

GOTO End

:Error
ECHO %_ERROR%
:: beep (ALT + 7)
ECHO 

:End

video_magic
23rd February 2005, 00:53
Thanks guys! I've just had an enjoyable time playing around with these.

esby: dnd works nicely. There is one option which I would like. At the moment it stores full paths in the m3u, But I would like an option whether or not to write full paths into the m3u. This would be handy if I save the mp3s and m3u onto CD backup, and they might be copied back to a different location in the future onto a different Windows setup on a PC.

dndc would not work for with just dndc c:\ (no m3us created anywhere).
But if I used dndc c:\ -wmyfile.m3u , then it worked in that it does create an m3u in each folder containing mp3s and it gives each m3u the name of that folder (excellent! :) ) and also the m3u doesn't contain full-paths, ...but it doesn't create any 'wmyfile.m3u' which I dont think is the expected behaviour :) - though what it does do is great and exactly what I want! :thanks:



:Iradic I tried the bat and it gave me some errors

C:\asblah>DIRMAGIC.BAT

'Volume' is not recognized as an internal or external command,
operable program or batch file.
'Volume' is not recognized as an internal or external command,
operable program or batch file.
Directory:
"C:\asblah"
Not valid directory name

UseMethod2
'TRUENAME' is not recognized as an internal or external command,
operable program or batch file.

C:\asblah>

I had saved the code as DIRMAGIC.BAT and run it from my c:\asblah folder, which contains an mp3. After I try to run it I lok in c:\asblah and there are 3 bat files have been created there - CALLMAIN.BAT which contains
Invalid parameter - ThisIsTrick

DIRECTORY.BAT which contains
SET _DIR=%2
SHIFT
:Loop
IF NOT "%2"=="" FOR %%X IN ( SET SHIFT GOTO:Loop ) DO %%X _DIR=%_DIR% %2

INVALID.BAT which contains
SET _DIR=%4

------
Also, where you say "just one thing ... you need to put your code to create m3u playlist..." and have put in your bat :: # PLACE YOUR BATCH CODE HERE !!!
I was not sure exactly how to put it so I have in there changed the line to:
:: # dir /B /O *.mp3 > ppp.m3u

I am not very advanced at this coding so I wasn't sure if that was right :o

Anyway guys, I really appreciate the time you have taken on this :thanks:

iradic
23rd February 2005, 12:33
i found this on the net
TRUENAME
This is an undocumented command in MSDOS since version 5.

The bad news is that TRUENAME absolutely will not work with long file names. It simply truncates the names until they fit in an 8.3 mask, and will happily give you the bogus name as a result. The good news is that if you change into a directory, running TRUENAME without arguments will give you the real legitimate short name of the directory.

you are probably on winxp/2k since this is dos command...

you shoud try to debug bat file... :)

i have winme and it works... i will try on my win2k machine to see how it works

also i thought you are experienced with batch files...

well main thing here is.... if you are running winxp/2k console you should execute for with /f switch ... if you are on win9x/dos console this bat should work...

i will try to play with this bat on my winme and win2k to improve it
and will post you result... (i see now there are some things to improve)...

bye

esby
23rd February 2005, 13:20
new version upped.
two bug fixes:
* command line parser corrected. All the parameters are analyzed now.
* added the call to the needed method for the 'auto' mode in the non console version.

esby

NB: in console mode,
you can use 'dndc . -wtoto.m3u'
It will scan the current directory and will use relative path (vs absolute).
I could enable the option for the gui, but supposing you drag others directory or folders, it could create invalid m3u files..., as the root folder would not be necessary in the same place.

video_magic
24th February 2005, 02:56
esby: Both console and DND version work great! :) I 'get' the go (auto) & go (save) now :stupid:; and it's so nice and easy with Windows Explorer using auto!. Default behaviour is not to save path info. Everything is exactly what I hoped, nice and easy and quick to use. The console version with dndc c:\ or dndc d:\ likewise :thanks:

Iradic: Yeah I am running XP pro (sp1). I'm far from advanced with any kind of programming, I sort of wade in and read & read and try things but always fail to get very far without losing the plot. I can do some HTML and simple batch files but not much more beyond that! :scared: I guess by debugging the bat you mean go line by line and see where it fails and why. I will certainly do my best.
Thanks very much for your time spent on it.

iradic
24th February 2005, 18:54
hi i made a new one...

summary:
it should work on winxp/2k (uses for with /f switch) then
accepts directory as input so you can use "send to" mouse right-click menu
under win9x/dos characters " " (space) "," ";" "=" will be replaced
by space (one or more consecutive with one space)

hope it works... bye


:: /? M3UMAGIC.BAT - create m3u playlist with directory name
:: /?
:: /? Usage: Place M3UMAGIC.BAT in directroy where you want playlist
:: /? to be created and execute it, use "/?" for this help screen
:: /? or use directory (full path) where you want playlist to be
:: /? created as input parameter
:: /?
:: /? WARNING: under Win9x/DOS don't use "Environment_OK" or "Parsing"
:: /? as first input parameter
:: /?
:: /? Limitations: really really long paths or names are not supported
:: /? (very very rare case)
:: /?
:: /? # see DIRMAGIC.BAT for more info
:: /?
@ECHO off
ECHO.

IF "%OS%"=="Windows_NT" GOTO WinNT
IF "%1"=="Environment_OK" GOTO Ok_to_Go
IF "%1"=="Parsing" GOTO Parse
IF "%1"=="/?" GOTO Usage

IF EXIST "%1.\nul" %1\
IF EXIST "%1.\nul" CD %1

ECHO Win9x/DOS detected...
ECHO Runing a new shell with environment big enough...

:: # run a new shell with environment big enough
:: 1024 bytes - increase if you get "Out of environment space" message
COMMAND /e:1024/c %0 Environment_OK
GOTO Dend

:Ok_to_Go

> CALLMAIN.BAT DIR *.none | FIND "Directory of" | FIND ":\"
:: output:
:: Directory of DIRECTORY_NAME
:: DIRECTORY.BAT %1 %2

> DIRECTORY.BAT ECHO SET _DIR=%%2
>> DIRECTORY.BAT ECHO SHIFT
>> DIRECTORY.BAT ECHO :Loop
>> DIRECTORY.BAT ECHO IF NOT "%%2"=="" FOR %%%%X IN ( SET SHIFT GOTO:Loop ) DO %%%%X _DIR=%%_DIR%% %%2

CALL CALLMAIN.BAT

ECHO Directory:
ECHO "%_DIR%"

%0 Parsing %_DIR%
GOTO Dend

:Parse
ECHO %1...
:: # FINAL PARSE DIR
::
> PARSEDIR.BAT ECHO IF "%%1"=="?[" GOTO FirstRun
>> PARSEDIR.BAT ECHO GOTO SecondRun
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :FirstRun
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO SET _DIR=%%5
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SET _DIR=
>> PARSEDIR.BAT ECHO SHIFT
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO :FirstLoop
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SET _DIR=
>> PARSEDIR.BAT ECHO IF "%%5"=="\" SHIFT
>> PARSEDIR.BAT ECHO IF "%%5"=="]?" GOTO End
>> PARSEDIR.BAT ECHO IF NOT "%%5"=="]?" FOR %%%%X IN ( SET SHIFT GOTO:FirstLoop ) DO %%%%X _DIR=%%_DIR%%%%5
>> PARSEDIR.BAT ECHO GOTO End
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :SecondRun
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO SET _DIR=%%_DIR%% %%2
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SET _DIR=
>> PARSEDIR.BAT ECHO SHIFT
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO :SecondLoop
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SET _DIR=
>> PARSEDIR.BAT ECHO IF "%%2"=="\" SHIFT
>> PARSEDIR.BAT ECHO IF "%%2"=="]?" GOTO End
>> PARSEDIR.BAT ECHO IF NOT "%%2"=="]?" FOR %%%%X IN ( SET SHIFT GOTO:SecondLoop ) DO %%%%X _DIR=%%_DIR%%%%2
>> PARSEDIR.BAT ECHO GOTO End
>> PARSEDIR.BAT ECHO.
>> PARSEDIR.BAT ECHO :End

:ChoiceOut

> CALLMAIN.BAT ECHO = | CHOICE /C=%2= CALL PARSEDIR.BAT ?
:Loop
SHIFT
>> CALLMAIN.BAT ECHO = | CHOICE /C=%2= CALL PARSEDIR.BAT ??
IF NOT "%3"=="" GOTO Loop
:: output:
:: CALL PARSEDIR.BAT ?[=,D,I,R,E,C,T,O,R,Y,=]?=
:: CALL PARSEDIR.BAT ??[=,N,A,M,E,=]?=
:: CALL PARSEDIR.BAT %1 %2 3 4 5 6 7 8 9 ...

CALL CALLMAIN.BAT

ECHO Directory name:
ECHO "%_DIR%"
ECHO.

ECHO Createing m3u playlist...
ECHO If you get "File creation error" message then dir path or name is too long
ECHO Shorten path or name and run this batch file again in that case
DIR /B /O *.mp3 > "%_DIR%.m3u"
ECHO.
GOTO End

:Usage
IF NOT EXIST "%0" SET _HELP=%0.bat
IF EXIST "%0" SET _HELP=%0
FIND ":: /?" "%_HELP%" | FIND /V "/V"
GOTO Dend

:WinNT
ECHO WinNT detected...
ECHO.
ECHO Createing m3u playlist...

IF EXIST "%1.\nul" %1\
IF EXIST "%1.\nul" CD %1

FOR /F %%I IN ("%CD%") DO DIR /B /O *.mp3 > %%~NI.m3u
GOTO Dend

:End
IF EXIST DIRECTORY.BAT DEL DIRECTORY.BAT
IF EXIST PARSEDIR.BAT DEL PARSEDIR.BAT
IF EXIST CALLMAIN.BAT DEL CALLMAIN.BAT
ECHO Done
:Dend

video_magic
27th February 2005, 00:53
Bat worked fine for me on Windows XP, thanks iradic! :)