feedburner

SUBSCRIBE ME

The FORMAT Command

Labels: , , , ,

To make a floppy or hard disk capable of storage, DOS creates tracks and sectors on a disk. This process of creating tracks and sectors on a disk is called formatting. To understand this concept better, assume that you have a long roll of blank paper. To make this roll of paper usable (for writing), it could be cut into pieces about a foot long, and then lines and page numbers could be put on every sheet. You could consider this to be the equivalent of formatting whereby the disk is made usable.

After formatting is complete, the disk is divided into tracks that are concentric circles. Tracks are further divided into portions called sectors. Data is stored on these sectors as magnetic patterns.

Each track and sector has a number. During formatting, DOS also checks for defective spots and displays the number of bad sectors on the screen.

Assume that you have bought a new floppy disk and want to copy some files from the C disk to this disk.

For this, you have to first format the diskette because a brand new diskette cannot be used for storing data. All new disks have to be formatted before data can be stored on them. However, some diskettes are pre-formatted by the manufacturer.

The command for formatting a floppy disk in the A drive is:

C> FORMAT A: <Enter>

After you issue this command, the following message appears:

C>FORMATA:

Insert new diskette for drive A:

And strike Enter when ready

At this point, you insert a blank, unformatted disk in drive A and press the <Enter> key to begin the format. When the format program has ended, the following message will be flashed on the screen:

Format another (Y/N)?

If you want to format another blank disk, you press Y (for yes) and insert another blank, unformatted disk in drive A. If you do not want to format another disk, you press N (for no) to end the format program.

Old disks that already contain data can also be formatted if data is not required and the disk is needed for usage. In this case, all the old data is lost after the formatting procedure is completed. This is usually done if an old disk has certain bad sectors and is needed for usage. The FORMAT command must be used with extreme caution. Any disk that you format will lose all the data that existed on it before the formatting operation.

It is very important that you specify the drive name while issuing this command. The proper syntax for this command is:

FORMAT<drive name>

Be careful when you use the FORMAT command and ensure that you enter the right drive name.

FORMAT is an external command. In order to execute this command, the DOS file FORMAT.COM must be present. In contrast, there will be no program file called DIR.COM to execute the DIR command.

F0RMAT.COM is usually available along with the DOS software.

If you wish to specify a volume label for your disk, you may do so with the FORMAT command. In this case, the N option may be used. A volume label helps in identifying the disk and can be up to 11 characters in length. The command to be issued to give a volume label to a floppy disk at the time of formatting is:

C>FORMAT A:/V <Enter>

Another option that can be used with the FORMAT command is /S. If you issue the command:

C:>FORMATA:/S <Enter>

The operating system files are transferred from the C disk to the A disk, and the disk will be formatted. Now this floppy disk can also be used to load DOS into the computer's memory. The system files cannot be copied using the COPY command. In order to use a floppy disk to load DOS, the disk has to be formatted using the/S option.

If the operating system software (DOS) is available on the hard disk, you are prompted to insert a DOS diskette in the A drive.

Using Wildcards with DOS commands

Labels: , ,

Using Wildcards with the DIR Command

Let us assume that you have forgotten the name of the file you created on the C disk, but you remember that the primary name starts with D and has five or less characters. If you try to locate your file by giving the DIR/P or DIR/W command, the large number of files on your disk would probably confuse you further. Instead, you could try the command:

C>DIR C:D????.* <Enter>

This would list all the file names starting with D and comprising five or less characters in the primary name, and any extension.

In all probability, you would recognize your file from the output of the above command.

Similarly, if you wish to view a list of files on the C disk, with the extension .EXE, the command you would use is:

C>DIR *.EXE <Enter>

Using Wildcards with the COPY Command

Let us assume that you wish to copy all files from the C disk with the extension .COB to the A disk. Instead of repeating the command for each file with the extension .COB, you can give the following command:

C>COPY *.COB A: <Enter>

Thus, with a single command, any number of files (with the extension .COB) will be copied. Without the facility of wildcards, copying all the .COB files one at a time will be tedious.

Let us take another example. To copy all files with primary names beginning with S and an extension of two characters or less, the command would be:

C>COPY S*.?? A: <Enter>

Using Wildcards with the DEL Command

Just as wildcards can be used with the DIR and COPY commands, they can also be used with the DEL command. However, this should be used with great caution.

To delete all files on the C disk, with the extension TXT, the command would be

C>DELC:*.TXT <Enter>

Similarly, to delete files with primary names beginning with X and an extension comprising two characters ending with A, the command would be

C>DELC:X*.?A <Enter>

Before using the DEL command with wildcards, you must be absolutely certain that you wish to delete all the files that match the specified pattern. Otherwise, you could lose some files that you actually want to retain.

The command

C>DEL C:*.* <Enter>

should be given with extreme caution because this would delete all files in the active directory of the hard disk. When this command is issued, DOS asks you if you are sure you want to delete the files.

Using Wildcards with Defined Paths

Wildcards can also be specified in file names as part of a command while using defined paths. For instance, if the active directory is the root and you wish to copy all files in the directory COBOL (with the extension .COB), from the C disk to the directory COBOL on the A disk, the command would be:

C>COPY \COBOL\*.COB A:\COBOL\*.COB<Enter>

This command would ensure that all files with the extension .COB in the COBOL directory on the C disk are copied onto the A disk in the directory COBOL. Similarly, paths can be used along with wildcards in other commands too. For example, to view a list of file names with an extension of one character or none in the ATTEND directory on the A disk, the command would be

C>DIRA:\ATTEND\*.? <Enter>

Even though the active drive is the C drive, the above command would list all file names on the A disk, under the directory ATTEND whose file names have an extension of one character or none.

If you wish to delete all files in the subdirectory DUE under the directory ADVANCE on the hard disk, the command would be

C>DEL\ADVANCE\DUE\*.*<Enter>

Using Wildcards ? and * Together

Labels: , ,

If you specify the wildcard pattern as PA???.*, all files with primary names beginning with PA and comprising five or less characters, and with any extension, will match the pattern. Instead of using the pattern PA???.???, it is simpler to use PA???.*.

Some more examples of patterns where both the wildcards are used together are given below:

TR??.*This will match all files with primary name beginning with TR and comprising four or less characters, and any extension.
T*.??This will match all files with primary names beginning with T and comprising any number of characters (upto a maximum of eight). The extension has to be of two or less characters.
???K.*This will match all files with primary names ending with K and comprising exactly four characters and any extension.
Z???Y. C*This pattern will match all files with primary names beginning with Z and ending with Y and comprising exactly five characters. The extension has to begin with C and may comprise any number of characters (subject to a maximum of three).

When specified in the file name as part of a command, wildcards provide greater flexibility and enable operations on a selective group of files that match the wildcard pattern.

Using the * Wildcard

Labels: , ,

If you wish to operate on the files whose primary names begin with A, you could specify the wildcard pattern as A???????.???.

This would match all file names beginning with A. However, using ? here proves to be very cumbersome. Instead of using ?, you could use the wildcard character *. The wildcard * can replace eight or less characters in the primary name and three or less characters in the extension. This is quite unlike ? which replaces only one character. The wildcard pattern which could be used here is A*.*.

From our first example, the file names that would match this pattern would be:

ABC. EXEAPP.COB
ATTN.TXTANN.TXT
ANNUALTXTANNUALCOB
ANNUALEXEATTLCOB

Let us take another example to understand this better. If you want to work on all files that have the extension .EXE, the wildcard pattern that could be specified is *.EXE. All file names with a primary name of any length and with an extension .EXE would match this pattern.

Thus, the ? wildcard provides character by character substitution, while the * wildcard is suitable when the number of characters to be matched varies.

DOS ignores any character which follows the * wildcard in the primary name upto the dot that separates the primary name from the extension.

For example, if you use the wildcard pattern *C.TEM, it would match all files with the extension TEM and not just those whose primary names end with C. The character C is ignored by DOS since it follows the * wildcard.

Similarly, if any character follows the * wildcard in the file name extension, it is ignored by DOS. For example, PAYROLLS.

Using the? Wildcard

Labels: , ,

Consider the wildcard pattern ????.COB. The following files will match from the list shown earlier:

        APP.COB                ONE.COB

        PEN.COB                ATTL.COB

Each ? can be replaced by one character or none. Since there are four ?s in the wildcard pattern, all files which have four or less characters in their primary name are listed by DOS.

DOS interprets a question mark in the same way as a card player interprets a joker—as a card that can substitute any other card.

Other characters can be intermingled with wildcard characters. An example is the wildcard pattern A???.COB.

This wildcard pattern will match all file names with primary names beginning with A and having four or less characters and the extension .COB.

From the files listed earlier, the following file names would be matched:

        APP.COB                ATTLCOB

If you have a file named PAINT.BAT and the wildcard pattern you specify is PA??T.BAT, the file PAINT.BAT will be listed.

Let us assume you have a file named SMS.PW and you wish to check if this file exists on the disk by using the wildcard pattern S7MS.PW.

DOS will display a message saying that the file has not been found. This is because ? can be matched by one character or none if it is specified at the end of a file name. However, when ? is specified in the middle of a file name, it has to be matched by exactly one character. The following example will illustrate this better.

Assume you have the following files on your disk:

        SIMPSON.KNG                PASTE.PAM

        TWINK.CS                        TWILIGHT.HZN

        PALE.PAM

The wildcard pattern you specify is P???E.PAM. Here the file PASTE.PAM will be matched and not PALE.PAM, even though their extensions are the same, i.e. PAM, and their primary names begin and end with the same letters. This is because the three ?s in the middle of the wildcard pattern must be matched by exactly three characters, like in PASTE.PAM. Similarly, each ? wildcard that is followed by other characters in a pattern has.to be matched by exactly one character.