1. Setting and Viewing Application Paths with the Path Command
The Path
command controls a very important environment variable. The path is the
environment variable that lets you access executables even if they
aren't in the current directory when at the command prompt. For example,
a typical path includes the \Windows\System32
directory on your machine so you have access to the majority of Windows
utilities. Without the path, you'd need to supply the path for every
command you want to execute. Imagine typing \Windows\System32\TaskList every time you want to discover which tasks are running on your system.
The problem is that
Microsoft can't anticipate every application path needed for your
system. For example, when you install SQL Server on a machine, you need
another path to access the SQL Server executables with ease.
Fortunately, many application vendors ease the use of paths by adding
them to the Windows permanent path. This registry setting contains the
paths to the applications you commonly use. However, sometimes you need
to add a path for just the current session. The Path command helps you make short-term path changes that affect a specific command window. This command uses the following syntax:
PATH [[drive:]path[;...][;%PATH%]
PATH ;
The following list describes each of the command line arguments.
drive
Specifies the drive to
use for the path entry. The default is to use the current drive,
current being relative to where you are at any given moment. Always
define a drive when changing the path to avoid unwanted drive reference
problems.
path
Specifies the absolute path to use for the entry. You can't use a relative path with the Path command. Separate multiple path entries with a semicolon (;).
%PATH%
Obtains the current
path environment variable value. In fact, you can access any other
environment variable by enclosing it within percent signs (%).
Typing Path at the command line and pressing Enter always shows you the current path. If you haven't changed the path in any way, the Path
command shows you the permanent path for your system. When you need to
add a temporary path, always type the new path information followed by
the %PATH% environment variable so
that you don't lose the current path information. Finally, if you really
do want to clear the path, Type Path;
followed and press Enter. This syntax clears the Path environment
variable for the current command window only; using it won't affect your
system as a whole.
2. Storing and Retrieving Directories with the PushD and PopD Commands
Windows maintains
a directory stack that you can use to store locations that you visit.
You use this stack to store directory information and then retrieve it
as needed. The PushD and PopD commands provide access to the directory stack and help you move around your hard drive more efficiently.
Think about a stack as
you would a stack of pancakes. Fry a pancake and you can add it to the
top of the stack. Get hungry and you can remove a pancake from the top
of the stack to eat it. The first (bottom) pancake on the stack is
always the last pancake off. When the pancakes are all gone, the stack
is empty.
|
|
If you move around your hard drive a lot, using the PushD and PopD
commands can save you considerable typing time. However, most people
use these commands to simplify batch files. No matter which way you use
them, the directory stack is a handy way for tracking your movement.
These commands use the following syntax:
PUSHD [path | ..]
POPD
The following list describes each of the command line arguments.
path
Specifies the
absolute or relative path to change to from the current location. See
the "Understanding Absolute and Relative Paths" sidebar for additional
details.
The PushD and PopD commands can also use command extensions to change to a network drive. When you use PushD in this manner, Windows automatically maps a drive to the network path for you. The PopD
command treats the networked drive as it would any other mapped drive
for your system.
3. Removing a Directory with the RD and RmDir Commands
The RD and RmDir
commands perform the same task; they remove an empty directory from
your hard drive. If you attempt to remove a directory that contains any
files, the command displays an error message. Removing old directories
cleans up the hard drive and makes it easier to find existing data. In
addition, each directory consumes a minuscule amount of space on the
hard drive that removing the directory frees. These commands use the
following syntax:
RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
The following list describes each of the command line arguments.
drive
Specifies the drive where the directory is located.
path
Specifies the absolute or relative path of the directory to remove.
/S
Removes all of
the subdirectories and files in the specified directory along with the
directory itself. This feature removes the safety feature that tells you
when a directory contains files, but does make these commands easier to
use within a batch file. This command line switch makes the RD and RmDir commands equivalent to the DelTree command.
/Q
Forces removal
of the directory tree without asking the user first. You can use this
option within a batch file to ensure the batch continues to run without
user intervention.