For this lesson we are going to fill in a couple of concepts that we will need before we go further with directories.
Wildcards are characters that can be used to stand-in for unknown characters in file names. In card games, a wildcard is a card that can match
up with any other cards. In DOS, wildcard characters can match up with any character that is allowable in a file name. There are two wildcards in DOS:
* = matches up with any combination of allowable characters
? = matches up with any single allowable character
Of course, since these two characters are used for wildcards, they are not allowable in filenames themselves. A filename like myfile?.txt would not be allowed. If you tried to create a file with this name you would get an error message “Bad file name.” But wildcards are very useful in any DOS command which uses a filename as an argument (which is most DOS commands, come to think of it.)
The asterisk character, *, can stand in for any number of characters. Some examples of this command:
This command would delete every file with the doc extension from the root directory of C: . So files like myfile.doc, testfile.doc, and 123.doc would all be deleted.
C:\>copy ab*.txt a:
This command would copy every file that began with ab, and had an extension of txt, to the floppy drive A: . So files like abstract.txt,
abalone.txt, and abba.txt would all be copied.
This is the fastest way to clean out a directory. This command will delete every file in the directory C:\temp\. The first apostrophe covers every filename, and the second one covers every extension.
The question mark wildcard, ?, stands in for any single character. Some examples of this command:
This command would only delete files that had a single character filename and a doc extension from the root directory. So a file like a.doc or 1.doc is history, but a file like io.doc is perfectly safe, since it has two characters.
C:\>copy ab?.txt a:
This command would copy any file with a three-letter name, of which the first two letters were ab, and with a txt extension, to the floppy drive A: . So files like abz.txt and ab2.txt would be copied.
You can combine these wildcards in any command as well.
This command would be very selective. It would look in the temp directory for files that had anywhere from 1 to 5 beginning characters, followed by ab followed by one character, and which had an extension of do followed by any one character. It would then delete any such files as matched. Examples of matching files would be itab3.dox, mearabt.doq, and 123abc.doc. But the file allabon.doc would not be deleted because it does not match. It has two characters following the letters ab in the filename, and the command specified one character in that position.
Every file in DOS has four attributes. These are:
As we saw in lesson 9, each file has an entry in the directory, and in that
entry there are four bits, one each for the four attributes. These attributes
are turned on if the bit is set to 1, and turned off if it is set to 0.
The Read-only attribute, if it is set to on, will let you read the contents
of a file, but you cannot modify it in any way. If you turn the read-only attribute off, you can modify, delete, or move the file.
The Archive bit is set on when a file is first created, and then set off when
the file has been backed-up by a good backup software program. If the file is ever modified, the archive bit is turned back on. That way, the software that does the backup can look at the archive bit on each file to determine if it needs to be backed up.
The System attribute is used to mark a file as a system file. In earlier versions of DOS, files marked “system” were completely off-limits without specialized utilities, but now the attribute serves mostly as a warning.
The Hidden attribute is used to prevent a file from being seen by other commands. If you try to clean out a subdirectory (such as by using the DEL *.* command), then try and remove the subdirectory, and then get an error that the subdirectory is not empty, you have a hidden file in there that was not deleted, even with the wildcards.
You can view the attributes for any file by using the DOS command ATTRIB. If you run the command without any arguments, you will get a listing of all the attributes that are turned on for every file in the subdirectory:
This will give you a list of the files in the C:\temp\ subdirectory, for every
attribute that is turned on you will see a letter (A for archive, S for system,
H for hidden, and R for read-only) at the beginning of the line.
You can also look at the attributes for any one file by including that filename (with an optional path) as an argument in the command:
And you can change the attributes for any file by making the following arguments in the command:
- +r = makes a file read-only
- -r = removes the read-only status, makes a file editable again
- +a = turns on the archive bit (i.e. flags this file as not having been backed
- -a = turns off the archive bit (i.e. shows this files as having been backed
- +s = marks the file as a system file
- -s = removes the system file designation
- +h = makes the file “hidden” to other commands
- -h = reveals the file to other commands
C:\temp\> attrib -h hidfile.txt
The file hidfile.txt will now be visible to other DOS commands.
You can chain these together if you wish:
C:\temp\>attrib -h -r myfile.txt
This will both reveal the file myfile.txt and make it editable and deletable.
With the two concepts of wildcards and attributes, we are ready for the next lesson, which will make us experts in using the DIR