Specification Shortcuts, Wildcards and Redirection
Shortcuts
A number of DOS commands recognize certain shortcuts when navigating between directories. The best known of these are:
Shortcut |
Why to use it |
. |
to refer to the current directory |
.. |
to refer to the parent directory |
\ |
to refer to the root directory of the current drive. |
drive: |
to refer to the current directory on drive |
Let us try to understand it with the help of examples. If the current directory on the c: drive is c:\windows\java\notes, then dir c: at the a:\> prompt will list the files in c:\windows\java\notes
- If the current drive and directory is c:\data\docs\letters, then:
Command |
. |
.. |
... |
\ |
CD
or
CHDIR |
Nothing.
Current directory stays as: c:\windows\ java\notes |
Change to parent directory: c:\windows\java |
Change to parent's parent directory:
c:\windows |
Change to root directory: c:\ |
DIR |
Displays contents of current directory:
c:\windows\ java\notes |
Displays contents of parent directory: c:\windows\java |
Displays contents of parent's parent directory: c:\windows |
Displays contents of root directory: c:\ |
- If the current drive and directory is c:\, then:
Command |
. |
.. |
... |
\ |
CD
(ChDir) |
Nothing - current directory stays as: c:\ |
Error message:
"Invalid Directory" |
Error message:
"Invalid Directory" |
Nothing.
Current directory stays as: c:\ |
DIR |
Displays contents of current directory: c:\ |
Error message: "Invalid Directory" |
Displays directories and extension less files of current directory |
Displays contents of root directory: c:\ |
Wildcards
Many DOS commands like, ATTRIB, COPY, DEL, DELTREE, etc., accept the use of the "wildcards" (* and ?). Generally terms, * refers to multiple characters and ? refers to a single character in a file or directory name.
This is the reason we can not use these characters in the name of any file. These Special characters are / \ : * ? < > “ | which should not be tried to insert in a file name. Following table shows the use of wildcards:
Wildcard |
What it does |
*.* |
All files with all extensions. |
*data*.* |
All files with "data" anywhere in its name. |
*array.* |
All files with names ending with "array" |
note?.cpp |
All files named "note" plus one character and with .CPP extensions. This file may be note1.cpp, but not note.cpp. |
?t*.* |
All files with an "t" as second letter in their names |
It should be noted that not all commands handle wildcards in exactly the same way. For example DIR * and DIR *.* are considered synonymous but DEL * would delete only files without an extension.
A space enclosed by inverted commas (" ") is accepted as a valid file specification by EDIT and DEL yet in rather different ways.
EDIT will open a file using the name of the current directory. Thus if the current directory is D:\windows\java\notes, EDIT " " will create a file in that directory called "notes".
DEL recognizes " " as *.* and will prompt for confirmation before deleting all files in the directory. As with EDIT, the number of spaces between the inverted commas does not seem significant but if there are no spaces an error message is displayed saying that a required parameter missing.
Unlike EDIT, a path can be included and, if it is, no spaces between inverted commas are required. i.e. to delete all files in the current directory:
DEL ./"" works, but DEL "" gives an error message.
COPY also sees " " as *.* and, like DEL, accepts a path with it. Unlike DEL, there must always be a space between the inverted commas, even when a path is included
|