The magazine of the Melbourne PC User Group

For %x in (*.*) ...
Tom Coleman

Last month's article finished up with an unexplained example of the FOR command which read as follows:
For %x in (*.*) do del c:\%x

I have been asked by a number of users just what it was and what use it is. I don't propose to delve into the obscure depths of DOS. It's spooky down there. However I will explain how to use this very powerful command. 

Have you ever accidentally copied a floppy into your hard disk? A hard disk that already had a bundle of useful files in it thus making DEL *.* too painful to get rid of the unwanted ones. I think we all have at some time. 

Now you could load Xtree or Norton's Commander, tag the offending files and delete them. That's one way. A simpler way would be to log on to drive A: with the original disk in that drive and issue the above command. 

You would have to modify the C:\%x to reflect the appropriate subdirectory. 

What this command does is to load whatever is enclosed in the brackets into the %x (it could be % any letter) one at a time and execute the command following the DO using the %x. 

This means that it would read all the filenames in drive A: and delete any file with the same name in drive C: (or where ever).

It's a bit lethal if one of the files is called COMMAND.COM, or CONFIG.SYS or AUTOEXEC.BAT or anything important. The rule is to check things out first and back up first. On the other hand you may have already overwritten them anyway. 

You can put anything between the brackets. For example, I use it to copy all my frequently used DOS files, utilities and batch files into a RAM disk which is the first item in my PATH. I do it in my AUTOEXEC.BAT. It tweaks a bit more performance from my XT. That part of the AUTOEXEC.BAT looks like this

CD\DOS 
FOR %%X IN (CHKDSK.COM FIND.COM ... etc) DO COPY %%X G: 

CD\Util 
FOR %%X IN (DIRS.COM BW.COM L.COM ... etc) DO COPY %%X G: 

CD\BELFRY 
FOR %%X IN (MM.BAT PDX.BAT BW.BAT ... etc) DO COPY %%X G:

Note the double % signs when used inside a batch file. (DOS throws the first one away). 

I can add or delete files by modifying what appears inside the brackets. 

As you get used to it you can do all kinds of interesting things but enough is enough - we don't want you blowing your fuses yet.

Reprinted from the September 1990 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]