CompTIA A_ Certification All-In-One Exam Guide, Seventh Edition - Michael Meyers [255]
1 file(s) copied
If you point the command prompt to the E: drive and type DIR, the README.TXT file will be visible. Let’s try another example. Suppose 100 files are in the C:\DOCS directory, 30 of which have the .DOC extension, and suppose you want to move those files to the C:\STEAM directory. Follow these steps:
1. Type CD\DOCS to point the command prompt to the DOCS directory.
C:\>CD\DOCS
2. Type MOVE and a space.
C:\DOCS>MOVE
3. Type *.DOC and a space.
C:\DOCS>MOVE *.DOC
4. Type C:\STEAM.
C:\DOCS>MOVE *.DOC C:\STEAM
5. Press ENTER.
C:\DOCS>MOVE *.DOC C:\STEAM 30 file(s) copied
The power of the COPY/MOVE command makes it rather dangerous. The COPY/ MOVE command not only lets you put a file in a new location; it also lets you change the name of the file at the same time. Suppose you want to copy a file called AUTOEXEC.BAT from your C:\ folder to a thumb drive, for example, but you want the name of the copy on the thumb drive to be AUTO1.BAT. You can do both things with one COPY command, like this:
COPY C:\AUTOEXEC.BAT E:\AUTO1.BAT
Not only does the AUTOEXEC.BAT file get copied to the thumb drive, but the copy also gets the new name AUTO1.BAT.
As another example, move all of the files with the extension .DOC from the C:\ DOCS directory to the C:\BACK directory and simultaneously change the .DOC extension to .SAV. Here is the command:
MOVE C:\DOCS\*.DOC C:\BACK\*.SAV
This says, “Move all files that have the extension .DOC from the directory C:\DOCS into the directory C:\BACK, and while you’re at it, change their file extensions to .SAV.” This is very handy, but very dangerous!
Let’s say, for example, that I made one tiny typo. Here I typed a semicolon instead of a colon after the second C:
MOVE C:\DOCS\*.DOC C;\BACK\*.SAV
The command line understands the semicolon to mean “end of command” and therefore ignores both the semicolon and anything I type after it. As far as the command line is concerned, I typed this:
MOVE C:\DOCS\*.DOC C
This, unfortunately for me, means “take all of the files with the extension .DOC in the directory C:\DOCS and copy them back into that same directory, but squish them all together into a single file called C.” If I run this command, Windows gives me only one clue that something went wrong:
MOVE C:\DOCS\*.DOC C
1 file(s) copied
See “1 file(s) copied”? Feeling the chilly hand of fate slide down my spine, I do a DIR of the directory, and I now see a single file called C, where there used to be 30 files with the extension .DOC. All of my DOC files are gone, completely unrecoverable.
XCOPY
The standard COPY and MOVE commands can work only in one directory at a time, making them a poor choice for copying or moving files in multiple directories. To help with these multi-directory jobs, Microsoft added the XCOPY command. (Note that there is no XMOVE, only XCOPY.)
XCOPY works similar to COPY, but XCOPY has extra switches that give it the power to work with multiple directories. Here’s how it works. Let’s say I have a directory on my C: drive called \DATA. The \DATA directory has three subdirectories: \JAN, \FEB, and \MAR. All of these directories, including the \DATA directory, contain about 50 files. If I wanted to copy all of these files to my D: drive in one command, I would use XCOPY in the following manner:
XCOPY C:\DATA D:\DATA /S
Because XCOPY works on directories, you don’t have to use filenames as you would in COPY, although XCOPY certainly accepts filenames and wildcards. The /S switch, the most commonly used of all of the many switches that come with XCOPY, tells XCOPY to copy all subdirectories except for empty ones. The /E switch tells XCOPY to copy empty subdirectories. When you have a lot of copying to do over many directories, XCOPY is the tool to use.
Their power and utility make the DEL, COPY/MOVE, and XCOPY commands indispensable for a PC technician, but that same power and utility can cause disaster. Only a trained Jedi, with The Force as his ally…well, wrong book, but the principle remains: Beware of the quick and easy keystroke, for it