Using Wildcards with DOS commands

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

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

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

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.

Need for Wildcards

Often, you may find that you need to operate on many files on a disk. Specifying one file at a time for one operation can be tedious. If these files have certain similarities in their file names, they can be referred to collectively using the wildcard facility provided by DOS. Suppose a disk contains the following files:

ABC. EXEANNUAL.COB
ATTN.TXTGO.EXE
APP.COBATTL.COB
ANN.TXTONE.COB
PEN.COBANNUAL.TXT

You may need to work on only those files whose primary name is less than, or equal to, four characters and whose file name extension is .COB. Instead of selecting these files one by one, you can use the facility of wildcards, whereby you can specify a wildcard pattern with a command. DOS will refer to those files whose names match the specified wildcard pattern. Let us look at how the wildcards ? and * are used in commands.

Displaying the Contents of a File - the TYPE Command

If a file PAYROLL.DAT exists in the current directory of your hard disk and you want to see its contents on the VDU, the command to do so is

C>TYPE PAYROLL.DAT <Enter>

You can also specify a path to DOS with the TYPE command. If the same file PAYROLL.DAT existed in the directory PAYMENT of the hard disk, the following command can be issued to display its contents:

C>TYPE C:\PAYMENT\PAYROLL.DAT <Enter>

If the file PAYROLL.DAT exists in the root directory of the A drive and you wished to display its contents, you have to specify the drive name before the file name. The command to do that is

C>TYPE A:PAYROLL.DAT <Enter>

Note: The Type command is useful for viewing text files.

Moving Files - the MOVE Command

The Move command allows you to move one or more files from one drive to another drive or from one directory to another directory. Assume that there is a file INTERNET.TXT under the directory INCOME on the hard disk that needs to be moved to a diskette. This can be done by issuing the following command:

C>MOVE C:\INCOME\INTERNET.TXT A: <Enter>

This command deletes the file physically from the hard disk and moves it to the target location.

Deleting Files - the DEL Command

You may discover that there are some files on the disk that you do not require anymore. Unwanted files occupy space on the disk. Therefore, it is desirable to remove such files. Assume that there is a file CON.BAK on the hard disk, which you do not require anymore and want to remove or delete. This can be done by issuing the following command:

C>DEL C:CON.BAK <Enter>

This command deletes the file CON.BAK from the hard disk. DOS does not, however, give any confirmation of deletion of this file. If you wish to delete a file from the A drive, you have to specify the drive A before the file name. For example:

C>DEL A:CONFIG.BAK <Enter>

You can also specify a path to DOS with the DEL command. If you wish to delete a file named LOCAL.3, which exists in the directory NETWORK on the C disk, the command you could give is

C>DEL C: \NETWORK\LOCAL.3 <Enter>

Renaming Files - the REN Command

Sometimes you may find that a name that you had given to a file initially is no longer suitable. If you wish to change the name, you need not copy it again under a different name. DOS allows the user to change the name of a file. This can be done by using the REN command. If you have a file named ZZZ.PIT and you now wish to rename it to LOAN.SUM, the command would be

C>REN ZZZ.PIT LOAN.SUM <Enter>

The file ZZZ.PIT will now exist under the name LOAN.SUM. Though the name has been changed, the contents of the file remain the same. A path can also be defined with the REN command. Let us assume that you wish to change the name of the file CALM that exists in the directory WEATHER on the C drive. The new name to be given is STORM. The command you could give

C>REN \WEATHER\CALM STORM <Enter>

BACKUP and RESTORE Utilities

BACKUP allows backing up of files from a hard disk to a floppy disk. In the event of a hard disk failure or accidental erasures, we can fall back upon the backed up data. It can also be used to backup from one floppy to another, even if they are of different types (different in size or capacity). BACKUP can copy files from within subdirectories as well.

BACKUP copies all source files into a single file, and maintains the list of file names in another file called the log file. If all the files cannot be stored on one disk, BACKUP requests for the next disk. The log file also stores the number of the backup disks on which the source files are stored.

The RESTORE utility helps you to restore files that have been backed up using the BACKUP utility. Files are transferred from a backup set to the location we specify.

While the earlier versions of BACKUP and RESTORE were command driven, the present day versions are menu driven and more of utilities than commands, and hence more user friendly.

Copying Files and Directories - the XCOPY Command

If you have a disk that contains files in subdirectories, and you want to copy the directories and subdirectories too, the XCOPY command should be used.

You could also use the COPY command globally, but this would copy the files of only the working directory and not subdirectories and its files.

The DISKCOPY command may also be used. However, the disadvantage is that it formats the disk, and copies the entire contents of one disk to another. You may, perhaps, not want to lose the existing contents of the target diskette. Also, you may not want to copy the entire contents of the source disk.

The XCOPY command has a major advantage over the other commands to copy files, because this command offers two special options. One of these options prompts you to specify the files that you wish to copy, and the other copies the directories and lower level directories. Besides, unlike DISKCOPY, XCOPY can be used to copy files from the hard disk too.

If you do not wish to copy every file on the disk, you may use the /P option with the XCOPY command.

For example, if you issue the command:

C>XCOPY C: \REPORT A:\REPORT /P <Enter>

DOS will prompt you with (Y/N), allowing you to confirm whether you want to copy each target file.

If you wish to copy the directories and lower level directories, DOS offers you another option with the XCOPY command. In this case you may use the /S option.

The command you could issue is:

C>XCOPY C:\REPORT A:\REPORT /S <Enter>

This command will copy the directory REPORT and all its subdirectories, unless they are empty.

If you do not specify /S with the XCOPY command, it works within a single directory.

Both the options can be specified in a single command. For example,

C>XCOPY C:\REPORT A:\REPORT /P/S <Enter>

You are advised to include the path and file name with the XCOPY command; XCOPY assumes that the operations are to be carried out in the currently active directory.

The program file XCOPY.EXE must exist in order to execute this command.

Copying the Contents of a Floppy Disk to Another - the DISKCOPY Command

If you want to copy the entire contents of one disk to another, you need to use the DISKCOPY command. This command copies the contents of the floppy disk in the source drive to the floppy disk in the destination drive. On a PC-XT with a single floppy drive, the same drive will have to be the source drive as well as the destination drive.

The command for copying the contents of one floppy disk to another is:

C>DISKCOPY A:A: <Enter>

This command copies the contents of the entire disk in drive A (source drive) to the disk in the destination drive, i.e. drive A. Here, drive A acts as the source drive as well as the destination drive.

When you issue the DISKCOPY command, the following message is displayed on the screen:

Insert SOURCE diskette in Drive A:
Press any key to continue...

DOS will wait for you to insert the source diskette and press any key, before continuing. After a while, the following message will be flashed on the screen:

Insert TARGET diskette in drive A:
Press any key to continue...

Here, you are prompted to remove the source disk and insert the target disk.

After the process of copying is completed, the display on the screen is

Copy complete
Do you wish to write another duplicate of this disk (Y/N) ?_

If you press Y, DOS will prompt you to insert another target diskette and another copy will be made. If you choose N, the display will change to C>.

The target diskette can be formatted or unformatted. If the target diskette is not formatted, DISKCOPY formats it. In case of a used floppy, the original contents are lost because DISKCOPY formats the disk before copying.

The DISKCCOPY command works only with floppy disks and cannot be used with the hard disk.

DISKCOPY is an external command. The file DISKCOPY.COM must exist in order to execute this command.

File Commands of DOS

DOS allows you to perform certain activities on the files on a disk, such as copying files, deleting them and renaming them. Let us take a closer look at the commands that instruct DOS to carry out these activities.

Copying Files - the COPY Command

If you have a file on the hard disk, you may want to copy it on to a diskette so that you can work with the same data on another machine. Or, you may want a copy of the data that is on a diskette onto the hard disk. Files can be copied from one disk to the other using the COPYcommand. This command also allows you to copy files to a different location on the same disk.

Copying a File to Another Drive under the Same Name

If you wish to copy the files on the hard disk to the diskette, which is in the A drive, the command is

C>COPY C:COMMAND.COM A:COMMAND.COM <Enter>

After the execution of this command, the file COMMAND.COM will exist on the diskette in the A drive, under the same name. After issuing the above command, the screen appears as follows:

C>COPY C:COMMAND.COM A:COMMAND.COM
1 File(s) copied
C>_

DOS displays the following message to indicate to you that the command has been executed:

1 File(s) copied

When using DOS commands, if the file names are not preceded by the drive name, they are assumed to refer to the active drive. Hence, if COMMAND.COM is on the C drive, which is currently active, referring to it as C:COMMAND.COM or COMMAND.COM means the same. But the files from the non-active drive must have the drive name preceding the file name.

If the name of the file is to remain unchanged, the file name need not be specified after the target drive (the drive to which the file is to be copied), which in the example illustrated, is the A drive.

Copying a File to Another Drive under a Different Name

You may want to make some changes in a particular file without losing the original file. If this is the case, you can copy the file on to another disk and work on the copy. You will probably want to give the copied file another name so that you can distinguish between the two files.

You can do this by specifying the new file name after the drive name.

For example, when you issue the command

C>COPY C:SAL.DAT A:SALARY.DAT <Enter>

the file SAL.DAT on the hard disk will be copied on to the diskette under a new name, SALARY.DAT. The contents of both the files will be the same after the file has been copied.

Copying a File as a New File in the Same Drive

Instead of making a copy of SAL.DAT on a diskette, you may want to make a copy on the hard disk itself. You can copy the file in the same drive by issuing the following command:

C>COPY SAL.DAT SALARY.DAT <Enter>

After the execution of this command, you will have the same file under two different names on the same disk.

Copying Files from One Directory to Another

Let us assume that you have created various files under the root directory. You later realize that some of these files are related to each other and you would rather put them together. Therefore, you make a directory to contain these related files. You will recall that issuing the MD command can do this, but this directory is not automatically going to contain the files that you wish to organize under it. However, you do not have to go through the long-drawn process of creating these files again under the new directory. DOS allows you to copy the files from the root directory to the new directory that you have created. For that matter, DOS allows you to copy files from any one directory to another.

Suppose you have a file named SAL.DAT (containing details of salaries of the employees) under the root directory. Since you have already created a new directory called EMPLOYEE and wish to copy the file SAL.DAT to the EMPLOYEE directory, you issue the following command to do that:

C>COPY C:\SAL.DAT C:\EMPLOYEE <Enter>

After issuing this command, the file SALDAT gets copied under the directory EMPLOYEE.

Similarly, you can copy files from one directory to another by specifying the path to DOS. Consider an example where a file NEWMAN.P exists under the directory ACTORS, which is under the directory FAMOUS on the C drive. If you want to copy it to drive A under the NAMES directory under the root, the command is

C>COPY \FAMOUS\ACTORS\NEWMAN.P A:\NAMES <Enter>

After this command is issued, the file NEWMAN.P will exist on the diskette under the NAMES directory.

File Commands of DOS

DOS allows you to perform certain activities on the files on a disk, such as copying files, deleting them and renaming them. Let us take a closer look at the commands that instruct DOS to carry out these activities.

Copying Files - the COPY Command

If you have a file on the hard disk, you may want to copy it on to a diskette so that you can work with the same data on another machine. Or, you may want a copy of the data that is on a diskette onto the hard disk. Files can be copied from one disk to the other using the COPY command. This command also allows you to copy files to a different location on the same disk.

Copying a File to Another Drive under the Same Name

If you wish to copy the files on the hard disk to the diskette, which is in the A drive, the command is

C>COPY C:COMMAND.COM A:COMMAND.COM <Enter>

After the execution of this command, the file COMMAND.COM will exist on the diskette in the A drive, under the same name. After issuing the above command, the screen appears as follows:

C>COPY C:COMMAND.COM A:COMMAND.COM
1 File(s) copied
C>_

DOS displays the following message to indicate to you that the command has been executed:

1 File(s) copied

When using DOS commands, if the file names are not preceded by the drive name, they are assumed to refer to the active drive. Hence, if C0MMAND.COM is on the C drive, which is currently active, referring to it as C:C0MMAND.C0M or C0MMAND.COM means the same. But the files from the non-active drive must have the drive name preceding the file name.

If the name of the file is to remain unchanged, the file name need not be specified after the target drive (the drive to which the file is to be copied), which in the example illustrated, is the A drive.

Copying a File to Another Drive under a Different Name

You may want to make some changes in a particular file without losing the original file. If this is the case, you can copy the file on to another disk and work on the copy. You will probably want to give the copied file another name so that you can distinguish between the two files.

You can do this by specifying the new file name after the drive name.

For example, when you issue the command

C>COPY C:SAL.DAT A:SALARY.DAT <Enter>

the file SAL.DAT on the hard disk will be copied on to the diskette under a new name, SALARY.DAT. The contents of both the files will be the same after the file has been copied.

Copying a File as a New File in the Same Drive

Instead of making a copy of SAL.DAT on a diskette, you may want to make a copy on the hard disk itself. You can copy the file in the same drive by issuing the following command:

C>COPY SAL.DAT SALARY.DAT <Enter>

After the execution of this command, you will have the same file under two different names on the same disk.

Copying Files from One Directory to Another

Let us assume that you have created various files under the root directory. You later realize that some of these files are related to each other and you would rather put them together. Therefore, you make a directory to contain these related files. You will recall that issuing the MD command can do this, but this directory is not automatically going to contain the files that you wish to organize under it. However, you do not have to go through the long-drawn process of creating these files again under the new directory. DOS allows you to copy the files from the root directory to the new directory that you have created. For that matter, DOS allows you to copy files from any one directory to another.

Suppose you have a file named SAL.DAT (containing details of salaries of the employees) under the root directory. Since you have already created a new directory called EMPLOYEE and wish to copy the file SAL.DAT to the EMPLOYEE directory, you issue the following command to do that:

C>COPY C:\SAL.DAT C:\EMPLOYEE <Enter>

After issuing this command, the file SALDAT gets copied under the directory EMPLOYEE.

Similarly, you can copy files from one directory to another by specifying the path to DOS. Consider an example where a file NEWMAN.P exists under the directory ACTORS, which is under the directory FAMOUS on the C drive. If you want to copy it to drive A under the NAMES directory under the root, the command is

C>COPY \FAMOUS\ACTORS\NEWMAN.P A:\NAMES <Enter>

After this command is issued, the file NEWMAN.P will exist on the diskette under the NAMES directory.

Changing Directories - the CD Command

Let us suppose that there are two directories in the root—LETTERS and INCOME. You have been working on the files under the directory LETTERS and now wish to work on the files in the directory INCOME. This means that you would have to change from the Letters directory to the Income directory and make the latter the active directory.

DOS allows you to change your directory by issuing the CD command. The command to make the INCOME directory active is

C>CD\INCOME <Enter>

where CDstands for Change Directory.

The command for getting back to the root directory is

C>CD\ <Enter>

The command for going to the parent directory is

C>CD.. <Enter>

So, if you are in the subdirectory PERSONAL (refer Figure 1.6), then the above command will take you to its parent directory, iie. the root directory.

If you want to see the name of the directory in which you are working, the command you give is:

C>CD <Enter>

Just typing CD will display the name of the active directory.

For example, if you are currently in the Income directory and you give the command to display the directory name, the screen appears as under

C>CD
C:\INCOME
C>_

This indicates that you are in the INCOME directory under the root directory.

Removing a Directory - the RD Command

If the files in a subdirectory are not required or have been removed, it may no longer be necessary to retain the directory. The RD command can be used to remove such a directory.

To remove the directory WASTE on the C drive under the root directory, the command to be used is

C>RD C:\WASTE <Enter>

If the directory to be removed is not in the currently active drive, then the drive name must be specified. A path can be specified with the RD command. If a directory OLDSALES exists under the SALES directory on C drive and has to be removed, the following command can be issued:

C>RD C:\SALES\OLDSALES <Enter>

Whenever you use the RD command, remember that it can only be used to remove directories that are empty and are not currently active.

Displaying Path of a Directory - the TREE Command

The TREE command is used to display the path of each directory, subdirectory and files. The TREE command is used as follows:

TREE C: <Enter>

This command displays the directories on drive C with ail its subdirectories. Similarly, to view the path of each directory, subdirectory and files on Drive A, the command is:

TREE A: <Enter>

If you want to view all the subdirectories of the directory EXPENSES, the TREE command can be used as:

TREE EXPENSE <Enter>

Making a Directory - the MD Command

You have identified the need for directories whereby files can be organized on a disk in a structured manner. If you want to bring together and store files pertaining to the employees of a firm and those pertaining to the stock of the firm separately, you can do so by creating subdirectories. Prior to the creation of directories all the files reside in one main directory, which is the root directory.

To bring together all the files pertaining to the employees, you can create a subdirectory called EMPLOYEE. The command to do this is:

C>MD EMPLOYEE <Enter>

where MD stands for Make Directory.

After this command has been issued, a subdirectory called EMLOYEE is created under the root directory.

Rules for naming a directory are the same as those for naming a file. Just as meaningful names are given to files, it is good practice to give meaningful names to directories. This is to enable you to identify directories easily.

Making a Directory on the A Drive

If you want to make a directory on the disk in drive A, you would have to activate the A drive by giving the following command:

C>A: <Enter>

This command makes the drive A active. Now you may issue the MD command and create a directory on the diskette in drive A. The command to create the directory EMPLOYEE on drive A is:

A>MD EMPLOYEE <Enter>

Managing Data and Software

Communications and Troubleshooting

NetWare Commands and Utilities

Introduction to Networks

Introduction to Local Area Network (LAN)

Inside the System Unit

Managing Hardware