Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 13th February 2005, 13:41   #1  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
DOS Batch file. How to rename a file to have the current directory name?

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
__________________
Thankyou!, I am grateful for any help
video_magic is offline   Reply With Quote
Old 14th February 2005, 12:08   #2  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
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
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 16th February 2005, 07:48   #3  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
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
__________________
Thankyou!, I am grateful for any help
video_magic is offline   Reply With Quote
Old 16th February 2005, 11:25   #4  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
just create your file with an absolute path,
and move it to where you might need it.

esby
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 16th February 2005, 14:04   #5  |  Link
aquaplaning
Registered User
 
aquaplaning's Avatar
 
Join Date: Apr 2002
Posts: 39
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:
Code:
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.
Code:
for /F %%I in ("%1") do dir /B /O %1 > %1\%%~nI.m3u
aquaplaning is offline   Reply With Quote
Old 16th February 2005, 17:16   #6  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
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
__________________
Thankyou!, I am grateful for any help
video_magic is offline   Reply With Quote
Old 16th February 2005, 22:18   #7  |  Link
aquaplaning
Registered User
 
aquaplaning's Avatar
 
Join Date: Apr 2002
Posts: 39
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
Quote:
for /F %%I in ("%1") do dir /B /O %1\*.mp3 > %1\%%~nI.m3u
aquaplaning is offline   Reply With Quote
Old 17th February 2005, 08:19   #8  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
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
__________________
Thankyou!, I am grateful for any help
video_magic is offline   Reply With Quote
Old 17th February 2005, 08:29   #9  |  Link
iradic
Registered User
 
Join Date: Jan 2004
Posts: 332
hm, not sure if it will work in DOS...
iradic is offline   Reply With Quote
Old 17th February 2005, 22:39   #10  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
Well... I guess the drag 'n drop version is only for Windows

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).
video_magic is offline   Reply With Quote
Old 17th February 2005, 22:48   #11  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
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
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 17th February 2005, 23:26   #12  |  Link
iradic
Registered User
 
Join Date: Jan 2004
Posts: 332
well /F switch isn't supported in DOS if command...

WinME with MSDOS 6.22

Quote:
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).

Last edited by iradic; 17th February 2005 at 23:30.
iradic is offline   Reply With Quote
Old 18th February 2005, 01:53   #13  |  Link
vhelp
Registered User
 
vhelp's Avatar
 
Join Date: Feb 2003
Posts: 299
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
__________________
ESC K7S5A / XP 1800+ / Windows 98
ADVC-100[dvio] / WTVGO[avio] / DC10+[avio] / Canon ZR-10 / Delphi 6 Personal / JVC S-VHS HR-S3910U / Durabrand SSS w/ DVD Player STS75E / Sony TRV-22
FithElement/Dogma/BladeRunner/Contact
vhelp is offline   Reply With Quote
Old 18th February 2005, 02:06   #14  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
no need for a component for drag & drop in delphi
Code:
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
__________________
http://esby.free.fr/

Last edited by esby; 18th February 2005 at 02:28.
esby is offline   Reply With Quote
Old 18th February 2005, 10:41   #15  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
Quote:
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
I've almost given up on looking on the net too unless anyone knows a better search engine than Google
__________________
Thankyou!, I am grateful for any help
video_magic is offline   Reply With Quote
Old 18th February 2005, 13:09   #16  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
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
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 18th February 2005, 20:48   #17  |  Link
iradic
Registered User
 
Join Date: Jan 2004
Posts: 332
why dont you try tag.exe?
iradic is offline   Reply With Quote
Old 19th February 2005, 16:59   #18  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
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 ; 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)
__________________
Thankyou!, I am grateful for any help

Last edited by video_magic; 19th February 2005 at 17:02.
video_magic is offline   Reply With Quote
Old 20th February 2005, 17:49   #19  |  Link
esby
Registered User
 
esby's Avatar
 
Join Date: Oct 2001
Location: france
Posts: 521
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
__________________
http://esby.free.fr/
esby is offline   Reply With Quote
Old 21st February 2005, 13:54   #20  |  Link
video_magic
Registered User
 
Join Date: Jan 2005
Posts: 368
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
__________________
Thankyou!, I am grateful for any help
video_magic is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:40.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2017, vBulletin Solutions Inc.