The magazine of the Melbourne PC User Group
A DOSKEY Macro
Tom Coleman
|
 |
Lots of users have DOSKEY loaded at start up, which means they have a line that reads something like:
C:\DOS\DOSKEY
in their AUTOEXEC.BAT file. Then they use it to recycle previous commands by using the up and down arrow keys, and some use the sideways arrows to move the cursor around the command line for editing.
Of course, some do not ever see the command line, so they miss out completely. If you are one of those who do not want to know about the command line then turn the page, read no more, go directly to gaol, do not pass Go and do not collect $200.
Now, those of you who are left, follow me.
Those who write the odd batch file should cock one ear. Those who do not write batch files should cock both ears. Here is a faster way of writing those quick and nasty batch files that you use to save keystrokes on repetitious tasks. Best of all it does not involve writing batch files, but just tacks a few DOS commands together. You can write batch files this way, too, but DOSKEY seems best suited to those shorties and on-the-fly quickies.
How you use it is up to you, but for illustration I am going to write a quickie to help me examine a pile of floppies, accumulated over time, the contents of which I have forgotten.
All I want to do is look at the disk in drive A: and either delete the files or replace the disk and have another go.
This will only delete files in the root directory. Any disks with read-only files and/or subdirectories will have to be put aside for more strenuous treatment with the all powerful and unforgiving ZOT command -more about that later.
If you were to key in all of the commands from the keyboard for every disk you would soon get bored and start taking longer as the typo rate increases. The sequence of actions and commands would be roughly:
Place disk in drive A:
DIR A:
Inspect output on screen
Either: Remove disk and start again, or
DEL A:\*.*
DIR A:
Remove disk and start again.
Nothing voodoo-like here. To turn it into an automatic process we need only two things. First, a way of stopping the process while we inspect the disk and, second, a way of sending the process back to the start. Actually there is a third requirement: we need to be able to tell the process when to delete and when to go back to the start, but that turns out to be something we do when we make up our minds, and not something we prepare using DOSKEY.
The magic word that stops the process is:
PAUSE
That stops everything and generates a "Press any key when ready" message.
If we now string all of the required commands together as a DOSKEY macro it should work. All DOSKEY macros must start with the command DOSKEY, then the name we want to give the macro followed by an equals sign (=) and each command is separated from the next with $T.
So the macro is written like this:
DOSKEY FLEA=DIR A:/P $T PAUSE $T DEL A:\*.* $T DIR A:
I called this one FLEA because I use it to clean up scratch disks. Now, when you type in FLEA the macro will start to execute. There is a problem here: sure, the macro stops while you read the directory listing, but what if you do not want to delete the files? Simple: if you do not want to delete the files just hold down the Control key and press the Break/Pause key (up there at the upper right of your keyboard). You can use Control+C instead, but Control+Break seems to work better.
Control+Break bombs you out of the macro. To start it again you can type FLEA again, use your arrow keys to recycle the original command, or press F3 and that will repeat the last command.
That's all that there is to writing a DOSKEY macro. You can write them to do anything that can be done from the command line.
Here is a hint for editing them. Write the macro and press Enter, which will run the macro. If it does not work, or you want to change it, just recycle your commands with the arrow keys. You will need to have DOSKEY loaded before you start, which can be done by having it loaded from AUTOEXEC.BAT or simply by typing DOSKEY and pressing Enter.
Here is another hint and a warning: these macros are held in memory and disappear down the electronic gurgler when you turn the power off. To make a permanent or renewable macro you will have to write it to a file, preferably a batch file.
Create a file called, say, DKMAC.BAT with each line the same as the line used to create the macro. That means you can write as many macros as you like, put them all in DKMAC.BAT and execute it from AUTOEXEC.BAT at startup.
Coming back to the original macro, FLEA; it does not delete subdirectories or read-only files. The following macro does but takes just a little longer:
DOSKEY ZOT=ECHO Y $B RECOVER A: $T DEL A:\FILE*.*
It deletes all files, subdirectories, read-only files, and even the disk label. It make boot disks blank and non-bootable. This is a reworked version of
ZOT.BAT described previously in PC Update.
With this procedure most recovery techniques will
not work if you make a mistake - it is deadly - so you have been warned.
For the nerds out there, the macros are executed before the internal commands in COMMAND.COM. For those who do not understand the significance of the last sentence, take a Melb PC training course where all that, and much more, is revealed
Reprinted from the May 1994 issue of PC Update, the magazine of Melbourne PC User Group, Australia
|