15.01.2024 Views

CompTIA A+ Certification All-in-One Exam Guide

  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Pruning and Grafting Folder Trees

There’s a number of situations where you find yourself wanting to grab a

folder, complete with all of the subfolders and any files that might be

anywhere in any of the folders, and copy or move the whole “pile” in one

command. We call this process pruning and grafting and it’s one of the

places where the command line really shines in comparison to GUI file

manipulation. Done properly, command-line pruning and grafting is faster

and gives you much finer control of the process.

In Windows, 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.) We’ll also

look at robocopy, cp, and mv.

xcopy

The xcopy command functions similarly to copy, but xcopy has extra

switches that give it the power to work with multiple directories. Here’s how

it does that. Let’s say I have a directory called Logs in the root of my C:

drive. The Logs directory has three subdirectories: Jan, Feb, and Mar. All of

these directories, including the Logs directory, contain about 50 files. If I

wanted to copy all of these files to my E: drive in one command, I would use

xcopy in the following manner:

xcopy c:\Logs e:\Logs /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.

robocopy

Microsoft introduced the robocopy command—short for Robust File Copy—

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!