how to write the syntax

Posted on 2002-04-11
Last Modified: 2012-06-27
how to wite the syntax to delete the program
acctually i have a syntax but it can't scan the c: drive
and also is it posible to do it

this is the syntax

FOR %%a IN (*.zip) DO del %%a <-- it's working but when u put it on e.g c:\windows folder then it only scan on the folder so how to make it so then scan all sub-subfolder to do a checking thank you
Question by:sol2k
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 6
  • +7

Expert Comment

ID: 6933351
I am not sure if this can help you.
I was using pkzip (DOS version).  Put the add and delete source file parameter to zip files specified.  Then you simply delete the newly created zip file.

Thus, files zipped will be deleted automatically (including sub-directories).  Then, you only need to delete the newly created zip file.
LVL 30

Expert Comment

ID: 6933834
If you are using NT and have command extensions enabled, you can do this:

for /R %%f in (*.*) do del %%f

Command extensions are enabled by using the /X argument with CMD.EXE: cmd /x

You also try the /S option on DEL if it is available:

del *.* /s

Good Luck,
LVL 48

Expert Comment

ID: 6934979
Better is a third party util.


This will let you include subdirectories in your deletion.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 6935711
thank you everbady for giving the command .steve i already try the syntax . but it doen't work .any syntax for me to do that in win9x.:)
acctually i want to create i program that can delete all the mp3 for every pc in my office .by doing the simple program that can run when the computer first startup
but now i only can create a program that del the mp3 when they is in the same folder.any suggestion for do it???

thank you

Author Comment

ID: 6943695
how is anyone can help me????to solve this problem???
how to make this program so then it can scan sub sub folder
to delete the file without put in every folder???

this is the simple syntax.

FOR %%a IN (*.zip) DO del %%a
LVL 48

Accepted Solution

dbrunton earned 15 total points
ID: 6943785
That command won't work for sub folders.  It doesn't go downwards.  Have you tried the util I recommended.  Here it is again

This will delete all subfolders for you.

Author Comment

ID: 6943999
can we run it when the computer was startup and don't have to type anything.
my situation is i have more then 100 pc in our office then what i need to to is to control the mp3 now i create 1 program so the everytime the computer start up all the mp3 file deleted by the program that's created

but anyway thank you for ur suggestion i try and explorer ur program 1st k
thank you very much for all experts give me a comment k

Expert Comment

ID: 6944055
As you have 100PC, I believe they are running on a network.  dbrunton's recommendation of should meet your requirement.  This utility is a freeware.  You can copy it to a share folder and then create a batch file with necessary parameters.  Finally, run this batch file from login script.
If they are standalone computer, you can run the batch from startup folder.

Expert Comment

ID: 6946017


The DOS 7.x (Windows 98) DEL command doesn't have the /S switch
for recursing subdirectories as in Steve's suggested NT/2K commands.
Your DEL version deletes files only in the current or specified directory.
Unfortunately your version doesn't have these practical enhancements.
The For loop syntax you posted:

FOR %%a IN (*.zip) DO del %%a the same as:


Using the For command eliminates the halting prompt;
All files in directory will be deleted!
Are you sure (Y/N)?
-if you're deleting with wildcards, like:

for %%a in (*.*) do del %%a

If you want a pure DOS method, I'll provide a script I use for recursion,
containing only internal commands and requiring no externals...
It works under DOS (tested on versions 5 and above) and Windows
and runs a command on the specified files in all directories.
If interested i'll paste a portion at the end of these comments,
scripted to delete files having a given extension.

Regarding monsterrick's method of using pkzip.exe to do it;
It will work but it's not with the "add and delete" parameters.
You can do it with the "Recurse" and "Move" (-rm) switches.
It's a neat idea, using a utility most people already possess.
Maybe not the fastest method, but here's an example script
using pkzip.exe to delete all .mp3 files from the current drive:

@echo off
pkzip -rpm \*.MP3 >nul
if exist del

The -p switch is also necessary for storing the path names
to ensure it includes multiple files having the same name.
Redirecting the pkzip screen output to the Nul device
keeps the display clean while it's working.

The recursion batch script i mentioned will do what you need,
but you may also want to consider a utility made for recursing.
I keep a few on a server that are made to recurse subdirectories
and search for and run certain commands on specified files.
I'll provide urls where you can download a couple of these.
Info and documentation is included but I'll give some examples
of deleting specific files. I'll use an extension of .TMP
and you can change it to .ZIP or .MP3 or whatever you need.

This first utility is named "TARGET" ...
It has numerous useful options for manipulating files...
You can run various commands on files meeting whatever criteria.
I'll just give some examples of deleting files, but glance through
its documentation to get some other ideas you might can use.

If you pass Target a filename specification with no parameters or switches,
it merely displays the names of those files found on the current drive, like:

Target *.TMP

To view the same files as above but only on the D: drive, do it like this:

Target D: *.TMP

Target provides a screen display of various file information
on the files it finds... (size, date, time, path, etc...)
You can have it display only the path and filename
by using its  -F  switch, like:

Target D: *.TMP -f

Try it and you'll see the difference... It's useful for logging purposes
when you need to redirect Target's output to a file, like:

Target D: *.TMP -f >log.txt

You can also eliminate Target's screen display output
by redirecting it to the NUL device, like:

Target D: *.TMP >nul

Here are examples of using Target to Delete files.
Again I'll use the extension of .TMP to illustrate...

To Delete files with Target, use its  -V  switch...
To delete all files having a *.TMP extension
and to have Target search only the F: drive,
specify the drive and use the  -V  switch, like:

Target F: *.TMP -v

To delete the same files as above
but on both the C: and D: drives, do it like this:

Target C: D: *.TMP -v

Using only the  -V  switch to delete files
instructs Target to prompt for a 'Yes' or 'No' before deleting...
To eliminate the prompt, use the  -N  switch with the  -V  switch, like:

Target C: D: *.TMP -v -n

To include Hidden and System files, use the  -Hidden  switch, like:

Target C: D: *.TMP -v -n -hidden

To have Target search all available drives for the specified files,
use Target's  -D  switch...
-e.g., To delete the specified files on all drives, without prompting,
you can do it like this:

Target *.TMP -d -v -n

Target has other methods and options available to maybe suit your needs.
It's a program that's been around for a while and continues to work well.

Here's an url where you can get the Target utility's documentation
and also download a copy of it:

Here's a link to just the Target executable:

This other utility is called "DELEN" ...
It's a utility for deleting files and can be made to
search entire drives and directories and subdirectories.
(Its default is to search only the current directory.)
It has several options allowing deletion of files
according to date, time, size, etc.,
or just by filename specification.

Delen has a switch you can use to merely display
the names of the files that would be deleted...
It's the  -N  switch (for Nothing) and you can use it for testing purposes.
I'll include it in all these examples... Remove it when you're ready to delete the files.

To have Delen delete all files having a .TMP extension
in the current directory, you do it like this:

Delen *.TMP /n

(Again, the /n switch tells Delen to not delete anything,
but to just display the names of the files it would have deleted.
Remove the /n when you're ready to delete the files.)

To delete all files having a .TMP extension in the root of the current drive
you can do it like this:

Delen \*.TMP /n

To do the same as above, but only in the root of a specific drive,
include the drive letter, like:

Delen C:\*.TMP /n

To delete all files having a .TMP extension on the specified drive,
but to also include all subdirectories as you need to do,
use the  /S  switch, like:

Delen C:\*.TMP /s /n

Delen will prompt for verification before deleting files...
To disable prompts, use the  /Y  switch, like:

Delen C:\*.TMP /s /y /n

To find and delete the specified files on both the D: and F: drives
and in all their directories and subdirectories without prompting, do it like:

Delen D:\*.TMP F:\*.TMP /s /y /n

Delen has a  /Q  switch (for Quiet) used to suppress screen output
of the deleted filenames and other messages while it's running,
or its output can also be redirected to the Nul device.

You can specify multiple drives and directories as the search criteria
and there are options for specifying file attributes and dates and times, etc...

There's a 16-bit and a 32-bit version of DELEN and I'll provide a link to each...
They're identical except that the 16-bit version also works under all dos versions
and the 32-bit version supports long file names. (Not an issue for your extensions.)

The downloaded zip file contains documentation and more examples.
Here's where you can get copies of both the 16-bit and 32-bit versions...

Delen  16-bit  ...  This version works under multiple os:

Delen  ver. 1.06  (w/ FAT32 support) ...
This version fixes a couple of bugs in previous versions
having to do with wildcard searches and this version
also recurses into Hidden and System directories:

If you're networked as monsterrick mentions then you can create a custom script
and have it silently search for and clean the desired files when needed.
You mention wanting a "simple program that can run when the computer first startup"
and needing to "run it when the computer was startup and don't have to type anything..."
Options include launching it from AUTOEXEC.BAT or from the Run= line in WIN.INI
or from the Registry or as monsterrick notes from the StartUp directory,
who might can help you configure it to run from one system.
Please post back if you need more info on that.

Here's my batch script for recursing subdirectories and deleting files.
It's coded to delete all files on the drive having a *.TMP extension.
You can edit the syntax to search for any valid file specification.
It can be run from any directory and will search the entire drive.
Replace only the extension part (the uppercase characters)
with .ZIP or .MP3 or whatever extension you're seeking...

@echo off
if exist rin1010 goto rin1010
dir/b/s \*.TMP >rin1010
%0 rin1010
for %%a in (%2...) do %2 if not exist %1 goto:it
for %%r in (md cd) do %%r @rin1010
>~add.bat echo @prompt call %0 rin1010 goto:seq=
ctty nul
>~bdd.bat %comspec%/c~add.bat
ctty con
for %%b in (@rin1010\~bdd.bat del) do call %%b @rin1010\~?dd.bat
del rin1010
for %%d in (rd goto:it) do %%d @rin1010
if +%3+==!! goto it
for %%a in (0 1 2) do shift
call del %0


Author Comment

ID: 6952398
rin1010 thank you for ur explaination :) it's very detail and good :) the delen utility can work both it's can work perfectly but i still want to try by msdos :) is it posible??? rin1010 ur script is only can run under v.5 only right? cos i try it .it's only can run in the same dir only to delete the file:)

ok let say if the dos is not posible to write the bacth to delete the file .then now i choose the delen for delete a file so how can i make it run under i know we need the delen program to delete the file for each pc :) is it?????

anyway thank you and sorry for lating reply the comment

Author Comment

ID: 6952447
can we create the simple program . this is my idea

using delen.exe than create a bacth file that link to the delen.exe to delete a mp3 file. and then compile it become a simple exe file .that combination delen.exe with batch file :0

if it is posible :)thank you

Expert Comment

ID: 6955837
At work I use a utility called SWEEP.EXE which will take any DOS command and execute it in the specified path and all subdirectories.

Tis very easy to use - email me and I'll send you a copy.

Stace (
LVL 48

Expert Comment

ID: 6956753
Syntax for delen for your use

delen     c:\*.mp3      /s   /q

This will silently delete all mp3 files on your hard drive.

Place that as the last line inside the autoexec.bat file on your computer and the job is done.  You will need to put the delen file inside the c:\windows folder.

Expert Comment

ID: 6958090


The script I posted works under versions 5.0, 6.xx and 7.xx ...
So it will definitely work for you in Windows 98 ...
I agree with your wanting to do it 'by msdos'
although my method is more suited to
individual machines and users.

The script illustrates that recursion can be done with internal dos commands
and how to run a command (in this case the delete command)
on files in a specified directory and its subdirectories.

The script identifies a list of files to process indicated by
the file specs entered. That example looks for files
having a .tmp extension in all subdirectories
on the current drive... i.e.,    \*.TMP

To do it on a specific drive, e.g., the C: drive as in your original question,
you can change that portion in the script and do it like this:


To delete all files with an .mp3 extension as you subsequently requested
and to work only in the Windows directory and all its subdirectories,
edit that part of the script to:


Be sure to change only the path and to copy the entire script as is...
It's okay to modify it, but if you do, run it on a test disk until you see how it works.
But considering your later questions, you'll probably want to use one of the
utilities mentioned, or a similar application, made for directory recursion.

One of those I mentioned as listed on a server is the Sweep app noted by Stace...
A reason I didn't include it (if it's the same Sweep.exe application) is because
it works only in the current directory and below and doesn't accept a path.
You need to 'cd' to the working directory before calling it.
Also it's slower than the others but it does work.
I keep the 16-bit and 32-bit versions and
if you want to look at it you can
download them from here:

Sweep.exe  ~  16-bit:

Sweep.exe  ~  32-bit:

Regarding your idea of "using delen.exe than create a bacth file
that link to the delen.exe to delete a mp3 file and then compile it
become a simple exe file that combination delen.exe with batch file"...

You can convert the batch file to a command file
and rename delen.exe to and compile the two.
But again, you need a call from a startup file to launch it,
which would in effect defeat the purpose.

The Delen syntax and other info dbrunton copied from my examples
should work if you're concerned with only one drive,
although the program can be placed in any Path directory,
or the path can be specified in conjunction with the command.
And you may need to call the commands from a login script
as monsterrick mentions.

So considering your new questions, you might have better results
with the Target.exe utility I described. It has switches that allow
searching of all available drives, including logged network drives,
and it's faster in most instances. It will read a set environment variable
where you can specify info on your particular volumes,
drive letters, user directories, etc...

Take a look at its documentation and the examples I posted and download it
and maybe give it a few tests to see if it can accomplish your current objective.
Please post back with your results and whatever other info you can provide on it...

Expert Comment

ID: 6964001
Find, and download Win95CMD.exe.  This will allow you to use the command extensions that are not normaly available in 9X systems.  Then adding the following command to the logon script will take care of your problem.

del c:\*.mp3 /s
LVL 48

Expert Comment

ID: 6964286
Aplogies rin1010

I am not reading these posts thoroughly.  I did not realise I was requoting your example.

Expert Comment

ID: 6966164
sol2k:  It is unclear to me exactly how you will execute the command on each of 100 computers.  Are you planning on adding the command to the users logon script?

Expert Comment

ID: 6966857

No apology necessary, dbrunton... Had to look
to see what you referenced... Didn't mean to imply
that you copied it but was mainly just redressing
the point that the program didn't necessarily
need to reside in the Windows directory.

Also see now although you didn't specifically reference Delen
the provided link is to a version of it, so perhaps I copied you, lol....
But we've both had similar questions before about recursive deletion.
That batch script was modified for sol2k from a script I provided in
previous questions and I try to keep various and latest versions
of tested and recommended deletion utilities on a server
to offer and avoid broken links. Might be feasible to
write a page of explanation and examples
to post or refer to when needed.

So in addition to the DOS method you requested, sol2k,
and the pkzip workaround / example and other info,
you have a selection of recommended utilities
that will accomplish your initial task.
Was it successful?

LVL 10

Expert Comment

ID: 6967906
@echo off
for /R D:\ %%a in (*.mp3) do del %%a>null

This work fine in a batch file with NT 4

What is your operating system ?

You maybe know you need to use one % on a command line and 2 %% in a batch or cmd file.

Expert Comment

ID: 6968709

Please review the questions and answers in the thread, LongBow...
SteveGTR earlier suggested the NT /r command and syntax...
Sol2k confirms it won't work... The OS is Windows 9.x ...
LVL 10

Expert Comment

ID: 6968826
Is Win9x an OS ?

Author Comment

ID: 7005098
sorry all experts due to lateing for giving the comment regarding the Q that i ask :)today i try the utillity for delen.and my plain is to pun the delen utillity for win9x and i try it .it's work perfectly in wn9x and to make my work simple i try the command in win2k then i try to put and write the syntax in autoexec.bat but :) the batch file is not running :) how to make make it runnig :) and i think winXP also have a some problem :)
thank you and if it's work then who should i give the points????? cos eveyone has contribute the knowleage and time so help me agian :)

thank you
LVL 48

Expert Comment

ID: 7005143
Points can be split.

Can you post the contents of your autoexec.bat file here.  And the syntax you are using.

Expert Comment

ID: 7007053


Windows 2K and XP versions don't process Autoexec.bat the same as 9.x ...
Depending on how you're running it under these or the Pro versions
you may need to use another method during startup...

Author Comment

ID: 7010001
thank you :) so how can i run the program b4 the windows load for win2k and XP??? what should i do and what utility i need if yes.
for win98 i use delen.exe so win98 is ok :) now is win2k n winXP :)

thank you

Expert Comment

ID: 7010896
You will not be able to run your script before windows starts on 2000, and XP systems.  The best bet for all operating systems is to run this in a logon script.  This method will not require you to make changes on every system on the network.  Just edit their login script.

Are your users actually logging on to the systems now with a domain account?

Are they running a login script?

Expert Comment

ID: 7012825


Other typical methods of automatically running programs when Windows starts
include using the "StartUp" folder and from the "Run" key in the Windows Registry ...

Place your command in the \Windows\Start Menu\Programs\StartUp folder
or create a new "String Value" and add your command to its "Value Data" field
under one of the following Registry keys:



Since this is a different question, you might consider closing the original
and asking another if you require further info about it... Hope this helps...

Author Comment

ID: 7012890
i know the step for do it ,but just want to make sure is it work or not :)but anyway thank you very much now the decision was close .and who should i give the point ?
if can i want to spilte the point to all of u :) thanks
very much
LVL 48

Expert Comment

ID: 7013198
To split points go here

and post a zero pont question there and ask to split this question.  Quote this link

so they know what question you are referring to.  Specify how you want to split the points and who to.give them to.

Expert Comment

ID: 7070067
As you requested, I have split points for you to all participants here:

Points for rin1010 ->
Points for Jason_S ->
Points for Longbow ->
Points for Stace ->
Points for monsterrick ->
Points for SteveGTR ->

Experts, please comment in your respective questions above to finalize this.

Moondancer - EE Moderator

Expert Comment

ID: 8672164
If your tired of the limitations and headaches of Windows .BAT and .CMD scripts, check out Cygwin, It's basicly a UNIX like shell that runs in Windows. You can write UNIX style scripts (using all your standard UNIX and Windows commands) and run them in Windows like batch files. You can even integrate Windows commands into the UNIX scripts. Cool stuff. I found it alot easier than trying to write complex batch files. By default Cygwin mounts your C: drive as /cygdrive/c, so you could do something like this...

cd /cygdrive/c
for files in $(find * | grep ".zip");do rm -Rf $files;done seeing how Cygwin is a real UNIX shell you can simplify complex tasks that would be a real pain in a Windows .BAT script. Here's the same command but this time it will log all the results.

cd /cygdrive/c
for files in $(find * | grep ".zip");do rm -Rf $files && echo "Deleted file $files" >> deleted_zips.log;done

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question