Сreating your own dos commands. Altering the system prompt. Searching through disk drive directories

Страницы работы

Содержание работы

                                                        Сreating your own dos commands

Most of this book has been concerned with BASIC programming tips and utilities.However, i've mentioned some of the interesting things you can do with PC-DOS, and it might be fun to slip in a few of them for you to play with. For example, wouldn't you like to create your own DOS commands?

I, for one, have not yet gotten accustomed to the PC's keyboard, and typing in DIR B: can be fraught with confusion as I try to remember to hit the Shift key to get the colon. I don't ever bother anymore. When I want to see the directory of drive B: I just type D B. If I happen to be logged onto B: I can just hit D.

Some of us are fair spellers, but have difficulty remembering acronyms and abbreviations. Is it “CHKDSK”, or “CHCKDSK” or what? No bother. With my computer system, I just type CHECK A or CHECK B to examine the desired drive.

This magic worked through BATCH files. These are system files, nothing more than ASCII text, with the BAT extension. When you invoke a batch file, the IBM PC will look at each line and attempt to execute it as were entered from the keyboard. On power up, the PC will look for a special batch file, AUTOEXEC.BAT. If it finds it, those commands will be executed automatically, without your needing to do anything.

Altering the system prompt.

AUTOEXEC.BAT is a good way to custom-configure your system the way you want it. You can run utilities that set the system clock to a clock board you’ve installed, activate a RAM drive, or do other tasks on powerup. Here’s a line that is in my own AUTOEXEC.BAT file:

A bit cryptic, right? PROMPT lets you alter the system prompt, using several special characters, each preceded by a dollar sign to differentiate the spetial characters from any other string you might want to include in the prompt. Here are the special characters that are legal:

So, typing PROMPT  $n$g would set the system prompt to the default drive name and the greater than symbol, like this:

That is the normal prompt setting. You can change the prompt to including the time, date, DOS version number, and other information as you want. Perhaps you have deciphered my own system prompt shown above. It looks something like this, as a two-line prompt:

I include the time, $t, followed by six backspaces, $h, so the second and fraction are written over.I care only about whole minutes. Then the prompt drops down a line and prints the normal default drive and “>” information. When i need to know the time, i simply press Return

key, and my system prompt tells me. The rest of the time the clock ticks away unobtrusively.

As a side benefit, i can tell at a glance how long it has been since i used mu PC. I press the Return key and compare with the system prompt above it.

Searching through disk drive directories.

There is one very important line you should include in you AUTOEXEC.BAT file, especially if you want to define your own DOS commands. That line looks something like this:

PATH A:\;B:\

That command, once invoked, will cause the system to search through the directories of your disk drives in that order when it cannot locate a batch file or command in the currently logged directory .

I repeat: the PATH command can tell DOS to look on other disk drives besides the currently

Logged disk for a batch file or command.

Do you understand what that means? If you have tried to load BASIC, which is stored on A: when you happen to be logged to B:, you probably have wished that DOS were smart enough to go look on a  different drive if it couldn’t locate a file. Well now, at least with command files and batch files, you can tell DOS to do that very thing! It makes it practical to use batch files as new DOS commands, because it does not matter where you happen to be logged when you decide to use a command. The command will be faster if it is located on the logged drive, but it will work on any drive that you have specified with the PATH  command.

Creating batch files

Now, on to the batch files themselves. When you type a file name with no extension, DOS first looks to see if there is a .COM or .EXE file with that name. Then it checks to see if there is a .BAT file that matches. If so, it will execute that batch file. If you wanted to invert a command called “CHECK”, which would invoke CHKDSK, you could create a batch file called CHECK.BAT with the single line: CHKDSK. Then, typing CHECK would summon CHKDSK automatically.

To write your own batch file, just copy from the console. Here is a sample session:

COPY CON : CHECK.BAT<ENTER>

CHKDSK<F6>

(1)  files copied

Using F6 instead of the Enter key ends your batch file input, while saving you a carriage return in the file. Now, the batch file you have just created is useful; however you can make it more so.

DOS allow you to specify up to 10 parameters on the same line as the command invoking the batch file. These parameters will be dropped into the batch file in the locations indicated by numbers you put there, “%0”, “%1”,”%2”,”%3”, and so forth. They will be included in the order you place them on the command line, but they do not have to be in the same order in the batch file. Try this line in your CHECK batch file:

CHKDS %1: /F

Now, from DOS you type:

CHECK B

When the batch file is executed, DOS substitutes the B parameters for the %1, and the command is now:

CHKDSK B: /F   

CHKDSK will do a check of drive B: plus fix any lost data, as directed by the /F switch. That’s all there is to creating that new DOS command. Try this one:

COPY CON: D.BAT

DIR %1: /W

Now, you can invoke D.BAT by typing:

D A or D B

And get the directory of the drive you want. The /W will display the directory in the wide format.You could substitute /P and have the directory shown in columns, but pausing when the screen is filled.

     Creating a text file.

Having difficulty remembering the syntax for certain DOS internal or external commands, like the MORE filter? We can’t have a batch file with the ssame name as a .COM or .EXE file, so I have created a file that shows me, page by page, a text file, from DOS, using MORE. I call it LOOK.BAT. This on needs two parameters, one for the file to be looked at and one for the drive on which it resides:

COPY CON : LOOK.BAT

MORE<%2 : %1

Now, I type LOOK MY FILE.TXT B, when I want to look at MY FILE, which is on drive B:.DOS substitutes, coming up with:

MORE<B:MY FILE.TXT

This happens to be the syntax, which I never remember, to use the MORE screen display filter on MY FILE. TXT, so I can look at it a screen at a time, with the – MORE – pause in between pages. It’s slick.

             More ways to use batch files   

Think of any command you’d like DOS to have. When I am on drive A:, but I’d like to be logged onto drive B:, and in BASIC, I just type BASICB, and guess what happens? You probably can create a batch file to implement commands of your own. Keep in mind the rules: no conflicts in batch file names between existing commands. Only 10 parameters, numbered %0 through %9, can be used, unless you use SHIFT, a batch file subcommand. That’s a bit complicated and not particularly useful since more than 10 parameters are unwieldy.

 Создание ваших собственных команд ДОСа

Большинство этой книги было заинтересовано ОСНОВНЫМИ программными подсказками и утилитами. Однако, я упомянул некоторые из интересных вещей, которые Вы можете сделать с ДОСОМ PC, и это могла бы быть забава, чтобы закрадываться в несколько из них для Вас, чтобы играть с. Например, разве Вы не хотели бы создавать ваши собственные команды ДОСА?

Я, со своей стороны, еще не привык на клавиатуру PC, и печатающий в ДИРЕКТОРЕ B: может быть чреватым беспорядком, поскольку я пробую не забыть поражать Клавишу SHIFT, чтобы получить двоеточие. Я когда-либо не беспокоюсь больше. Когда я хочу видеть справочник двигателя B: я только тип D B. Если я, случается, зарегистрированы на B: я могу только поразить D.

Похожие материалы

Информация о работе