Google Answers Logo
View Question
Q: Help with coding a simple MSDOS BAT file. ( Answered 5 out of 5 stars,   5 Comments )
Subject: Help with coding a simple MSDOS BAT file.
Category: Computers > Programming
Asked by: jpalme-ga
List Price: $15.00
Posted: 20 Apr 2003 01:55 PDT
Expires: 20 May 2003 01:55 PDT
Question ID: 192896
I want a BAT file which will change the structure of the Windows 98
folder "My Music" on the hard disc C:. I want the BAT file to go
through all immediate subdirectories in "My Music". If any directory
contains a file with the Windows 98 name "Unknown", then all files in
"Unknown" are to be moved to the directory in which the directory
"Unknown" resides. After this, the "Unknown" directory (now empty) is
to be deleted. This should be done for all subdirectories of "My

Clarification of Question by jpalme-ga on 21 Apr 2003 01:00 PDT
I thought BAT files could do it, but if you say they won't, you
probably know this much better than me.

Would it work if I could enumerate the actual names of the
subdirectories directly under "My music". Their Windows names tend to
be the same, I do not know how to find the MSDOS name of a file. Such
a solution must also work in case some of the enumerated subdirectory
names do not exist at a particular time.

The alternative of a program in PERL would also be OK for me, if
someone else writes it for me, and tells me how to install PERL on my
computer. Since this a private need I have, not business, I am not
willing to pay a lot for a solution, but my offer of $15 is still

I mostly use a Macintosh, and I have appletalk between the Mac and the
Windows machine, so a third solution might be to write an applescript
solution for the Mac which moves the files remotely on the PC. I could
to that myself, if that is the best solution to my problem.

Clarification of Question by jpalme-ga on 21 Apr 2003 01:04 PDT
What is "popsracer-ga"? I searched for it with Google and foud no match!

Request for Question Clarification by theta-ga on 22 Apr 2003 07:28 PDT
Hi jpalme-ga,
  While what you require is not possible with Windows Batch files, it
is quite easy to achieve using the Windows Scripting Host[WSH]. WSH is
Microsoft's replacement for the aging BAT files, and has been shipping
as part of every version of Windows since Windows 98. It allows you to
program your batch files using VBScript, Jscript and other scripting
languages. For more information on the Windows Scripting Host, please
check out the following pages:
   - MSDN Online: Windows Scripting 
   - Microsoft Windows Script Host: A Universal Script Host for
Scripting Languages
   - Windows Script Host 5.6  
  If you are running Windows 98, you probably have WSH 1.0 installed.
You can check the installed version by giving the command
on the command prompt.
You can download the latest WSH 5.6 [719 KB] from Microsoft's website:
   - Windows Script 5.6 for Windows 98, Windows Millennium Edition and
Windows NT 4.0

  I have already written and tested a VBScript solution which meets
your requirements. Just to be clear about your needs, this is what the
script does:
  - Looks in the *immediate* subfolders of the My Music folder. It
requires you to provide the path to the My Music folder at the
  - If any of the *immediate* subfolders contain a subfolder named
"Unnamed", all the files contained in the "Unnamed" folder are moved
to its parent folder, and the "Unnamed" folder is deleted.
  Please specify if you need any changes made to the working of the
batch script. The script was successfully tested on a Windows 98
computer with WSH 5.6 installed.

 I am not posting the code yet since you have not specified whether
you will accept solutions employing WSH as an answer. If you agree to
a WSH based solution, I will post my code, incorporating any changes
you might specify, as the answer.


Request for Question Clarification by theta-ga on 25 Apr 2003 07:02 PDT
Hi jpalme-ga,
   Are you still interested in an answer to your question?
   If you have already found a satisfactory solution, please close
this question by clicking on the "Close Question" button at the top of
the page.

Clarification of Question by jpalme-ga on 25 Apr 2003 11:32 PDT
Thank you very much, all of you who have tried to help me. Even if you
have not done the job, you have saved me many hours of trying to get
.BAT files do things they apparently cannot do.

I will write a solution in Applescript on my Macintosh, which will
remotely access the Windows 98 computer via Appletalk. That is the
simplest solution for me.

Request for Question Clarification by mathtalk-ga on 01 May 2003 09:15 PDT
Hi, jpalme-ga:

Please take a look at my comment at bottom.  If you no longer want
help with creating the BAT file, you might want to indicate this by
expiring your question.  If you would like to have the details per my
comment, please let me know that you are still interested.

regards, mathtalk-ga

Clarification of Question by jpalme-ga on 02 May 2003 00:08 PDT
I did that, I wrote 
CD \"My Music"
 and then
and got the following listing:

VETENS~1       <KAT>        03-04-27   9.16 Vetenskaps Redaktionen P1
SVERIG~1       <KAT>        03-04-27   9.18 Sveriges Radio P1-s
SVERIG~2       <KAT>        03-04-27   9.29 Sveriges Radio P1
PROGRA~1       <KAT>        03-04-27   9.32 Programmet d—r h—lsan inte
tiger still
ENRESA~1       <KAT>        03-04-27   9.34 En resa genom tiden
INTETM~1       <KAT>        03-04-27   9.37 Intet m—nskligt —r oss
SVERIG~3       <KAT>        03-04-27   9.39 Sveriges Radio - Ekot
SRRADI~1       <KAT>        03-04-27   9.49 SR Radio Sweden
SRMALM~1       <KAT>        03-04-27   9.52 SR MalmÓ
OMMťNN~1       <KAT>        03-04-27   9.59 Om m—nniskor och samh—lle
OMVŤRT~1       <KAT>        03-04-27  10.04 Om v‹rt svenska spr‹k
P1-SAK~1       <KAT>        03-04-27  10.06 P1-s aktuella magasin
VETENS~2       <KAT>        03-04-27  10.50 Vetenskapsredaktionen P1
EVIGTO~1       <KAT>        03-04-27  11.03 Evigt och aktuellt om
kvinnors liv

I know that the immediate subdirectories below these directories all
have the Windows-98 name "Unknown" but I do not know how to find out
what the MSDOS names are of those subdirectories. I tried
CD \"My Music"\"EVIGTO-1"
but none of these commands seems to work.

Request for Question Clarification by mathtalk-ga on 02 May 2003 19:12 PDT
Hi, jpalme-ga:

The first column contains the 8.3 names.  So after:

CD "My Documents"\"My Music"

gets you into the main subdirectory you're interested in, you should
do, for example:


to see the contents there.  Note that the pentultimate character is a
tilde ~ and not a minus -.

It would be helpful to see the contents of such a subdirectory posted
as a clarification, just to make sure we are in sync on what you are
calling a subdirectory with name "Unknown".  Since "Unknown" is only
seven characters, the MSDOS and Win98 names for this folder will
presumably be the same.

regards, mathtalk

Clarification of Question by jpalme-ga on 03 May 2003 01:28 PDT
I am overwhelmed by all the answers I have got to my query.
Yes, I seem to have CSCRIPT version 5.6 installed on my
Windows 98 computer, and a CSCRIPT solution sounds
perfect for me. Please post the code!

I am not 100% sure if the subwindows below "My Music"
are named "Unkown" as their MS DOS name. I know
that their Windows 98 names are "Unknown" but do
not know how to find what their MS DOS name.

(The directory structure, which I want to simplify, is
the results of running the "Convert media format"
command in Realbrowser. Why Realbrowser
creates this subdirectory structure, I do not know.
It confuses my MP3 reader, that is why I want the
format simplified.)

How do I instruct Google to pay for the solutiuon?

Request for Question Clarification by mathtalk-ga on 03 May 2003 07:03 PDT
Hi, jpalme-ga:

You previously posted a partial "directory" listing (the output of the
DIR command) of your "My Music" directory.  As you will see from that
output, the Windows 98 "long names" appear on the right hand; the
MSDOS 8.3 "short names" appear in the first column, to the left hand. 
In between there's a column that identifies directories (vs. files)
and a timestamp.

Thus in the example you tried to work with before, a subdirectory
whose long name is:

Evigt och aktuellt omkvinnors liv

has this short name:


and a timestamp of 11:03 AM on April 27, 2003.

When a Windows 98 filename (or directory name) is as short as
"Unknown", the long and short names should agree.  You can verify that
by using the DIR command within the EVIGTO~1 directory.  Then you will
see both the "long" and "short" names in separate columns, as just

You will not be charged your offered list price of $15 until a
researcher posts an "Answer" to your question.

From your mention of having "CSCRIPT" installed and wanting to have
the code posted, I infer that you would like theta-ga to post an
answer with a scripting solution.  To make it perfectly clear, you
might post a clarification saying something like:

   "THETA-GA :  This customer wants your answer!"

regards, mathtalk-ga

Clarification of Question by jpalme-ga on 05 May 2003 04:46 PDT
Yes, I think the solution suggested by theta-g sounds good, and would
like his or her WSH script, which seems to be the solution to my

Request for Question Clarification by theta-ga on 05 May 2003 23:32 PDT
Hi jpalme-ga 
  Sorry for the delay in replying. I will post the required script soon.
Subject: Re: Help with coding a simple MSDOS BAT file.
Answered By: theta-ga on 08 May 2003 10:35 PDT
Rated:5 out of 5 stars
Hi jpalme-ga ,
    I have uploaded a zip file containing the required WSH script to
my server.
- You can download it from:
    [ ]
- The Zip file( contains the WSH script
file(FileMove.wsf). Extract this file to a directory of your choice.
- To run the script, all you need to do is click on it. Once the
script is done, a "Script Done." message will be shown.

  The script looks in your "C:\My Music" folder for any subfolders. If
any are found, they are checked for an "unknown" subfolder. Any files
contained in the "Unknown" folder are then moved and the folder is

  If you want the script to look inside some folder other than "C:\My
Music", then you can open the script file "FileMove.wsf" in Notepad,
and edit the variable BASEDIR to point to the required directory.

Hope this helps.
If you have any queries or require any changes made to the script,
just post a request for a clarification and I will be glad to help you
Please do not rate this answer unless and until you are completely
satisfied with the solution.

Request for Answer Clarification by jpalme-ga on 09 May 2003 01:53 PDT
Sorry, I could not download that file.

Clarification of Answer by theta-ga on 09 May 2003 06:31 PDT
Hi jpalme-ga,
   I have checked out the download, and it works fine for me. I
recommend that you try downloading the file again.
   In case you continue having problems downloading the file, I'm
posting the code for you here.
   - Create a new file using any text editor, and name it FileMove.wsf
   - Paste the following code(given below inside the BEGIN and END
tags) into the file you just created, and save the file.
************** BEGIN SCRIPT CODE *****************

<job id="FileMove">
<script language="VBScript">


BASEDIR = "C:\My Music" ' Base folder name
DIRNAME = "Unknown"     ' Directory to search for

'Start scanning the folders
WScript.Echo "Script Done."

'Function scans the base folder looking for any
'subfolders. If any subfolders are found, they 
'are sent to the SearchUnknown function
Function ScanFolders(folderspec)
 Dim fso, fldrs, f, subFolders
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set fldrs = fso.GetFolder(folderspec)
 Set subFolders= fldrs.SubFolders

 For Each f in subFolders
   SearchUnknown(f.path) 'Search within subfolder

End Function

'This function scans the given folder to see if a
''Unknown' folder is present or not.
Function SearchUnknown(folderpath)
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f = fso.GetFolder(folderpath)
 Set sf = f.SubFolders
 For Each f1 in sf
  if UCase( = UCase(DIRNAME) then
    'Enable error handling
    On Error Resume Next  
    'Move all the files  
    fso.MoveFile f1.path & "\*.*",folderpath 
    If Err.Number <> 0 Then
  Wscript.Echo "The folder: " & vbcrlf & _
  "   " & f1.path & vbcrlf & _
  " will not be deleted since the following error" & _
  " occurred while trying to copy files from it: " _
  & vbcrlf & "   " & Err.Description
      fso.DeleteFolder f1.path 'Delete folder
    End If
    On Error GoTo 0 
  End if                  
End Function


************** END SCRIPT CODE *****************

- To run this script, all you have to do is click on the FileMove.wsf
  NOTE: If you have the latest version of Norton Antivirus installed
and have 'Script Blocking' enabled, you may get an alert message about
a possibly malicious script. This happens because the script accesses
your folders in order to check their names and move files. Just select
"Authorize this script" from the Action list, and the message will go
away forever.

Hope this helps. 
If you have any queries or require any changes made to the script,
just post a request for a clarification and I will be glad to help you


Request for Answer Clarification by jpalme-ga on 11 May 2003 04:16 PDT
Now my only problem is to find out how to close a question when I have
received a well-working reply!

Clarification of Answer by theta-ga on 11 May 2003 07:02 PDT
Hi jpalme-ga,
   Glad to have been of help. Thanks for the great rating!
jpalme-ga rated this answer:5 out of 5 stars
Thank you, it works perfectly! You have made me happy today!

Subject: Re: Help with coding a simple MSDOS BAT file.
From: popsracer-ga on 20 Apr 2003 02:59 PDT
I think it is not possible to this solely with batch files under
Windows 98.
The trouble is finding some way of iterating trhough all the
subdirectories in the "My Music" directory.  Under Windows NT/2000/XP
the FOR command as has /R option that walks thorugh a subdirectory
tree, then it is a simple matter of using IF to check if a file exists
then doing a delete on directories that contain that file.
I believe under Windows 98 this option does not exist on the FOR

You could easy use a third-party utility to provide the functionality
that FOR provides or alternatively use a scripting language with
greater functionality such as PERL.
Subject: Re: Help with coding a simple MSDOS BAT file.
From: arcadesdude-ga on 20 Apr 2003 04:24 PDT
popsracer-ga might be right. I just checked for /? on Windows 98 and
here is the output:

C:\WINDOWS\Desktop>for /?
Runs a specified command for each file in a set of files.

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

  %variable  Specifies a replaceable parameter.
  (set)      Specifies a set of one or more files.  Wildcards may be
  command    Specifies the command to carry out for each file.
             Specifies parameters or switches for the specified

To use the FOR command in a batch program, specify %%variable instead

There is no /r option on Windows 98 for the for command in dos.
Subject: Re: Help with coding a simple MSDOS BAT file.
From: mosquitohawk-ga on 20 Apr 2003 14:35 PDT
Switch to Linux.  :)
Subject: Re: Help with coding a simple MSDOS BAT file.
From: chris2002micrometer-ga on 21 Apr 2003 21:14 PDT
It's probably possible, but not doable in an hour. You might try some
offshore resources like
Subject: Re: Help with coding a simple MSDOS BAT file.
From: mathtalk-ga on 26 Apr 2003 22:30 PDT
Hi, jpalme-ga:

A .BAT file can do this in a fairly straightforward manner, if the
names (or potential names) of the immediate subdirectories below "My
Music" are known in advance (which you indicated was possible).

If you open a DOS command box and change to the "My Music" directory
(probably on your C: drive, under "My Documents"), then execute:

C:My Music> DIR *. 

you'll see a listing of all the directory names, with the old 8.3
versions in the first column and the "long name" versions on the end. 
This assumes Win98.  In the NT family of operating systems you'd use
DIR *. /X to get the "DOS" names of files (and directories).

What I'd do is to "capture" these DOS names into a text file with:

C:My Music> DIR *. > mytext.txt

and then edit the text file produced (which now has the directory
names) into a batch file that does the copying and directory removal
(subject to testing for the existence of the potential directories).

Let me know if you'd like more details posted as an answer; the
Applescript solution sounds pretty elegant too.

regards, mathtalk-ga

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy