WINDOWS COMMAND PROMPT

LESSON –
COPYING & MOVING

 

separator-blank.png

 

GROUP WORK

 

STEP 0 – SETUP

 

·       In windows, unzip this file and copy its contents to the cmdWork folder that you created in the previous lesson.

 

·       Open the command prompt and navigate to the Lesson04Work directory which is inside the cmdWork directory.  This is where we will do our work for now.

 

STEP 1 – CD WITH RELATIVE PATH

 

·       Once inside Lesson04Work, navigate to Rockstrz\That\Are

 

·       Note that you can do this using a single command if you want:

    cd Rockstrz\That\Are

 

STEP 2 – CONCEPT (EXAMINE A FOLDER STRUCTURE)

 

·       Take a minute to understand the directory structure. 

You can use
dir /s for this.  Or you can simply navigate through the different directories and see what is there.

 

·       Go back to the Are directory.

 

STEP 3 – COPY

 

·       Let’s copy the file pink.txt to the directory awesome by using:

        
copy pink.txt awesome

 

·       Verify that the file pink.txt is still in the current directory and in awesome.  So it has been copied.

 

STEP 4 – DEL

 

·       In the Are directory, delete pink.txt using:

del pink.txt

Note that by copying a file and then deleting the original, you have just moved the file to a different location.

 

STEP 5 – MOVE

 

·       Instead of copying and deleting, we can simply move a file to a different location.

·       Let’s move the file yankovich.txt to the directory weird by using:

        
move yankovich.txt weird

Notice that both
copy and move work in a very similar way.

 

STEP 6 – COPY OR MOVE TO A PATH

 

·       We can copy or move a file to a path location.  The path could be absolute or relative.

         move britney.txt super\awesome

STEP 7 – COPY OR MOVE UP ONE LEVEL

 

·       We can copy or move a file up one directory level by specifying the destination folder as ..

 

·       Go into the weird directory and move the file yankovich.txt back one level into Are by using:

         move yankovich.txt ..

 

STEP 8 – COPY OR MOVE UP TWO LEVELS

 

·       We can copy or move a file up two directory levels by using ..\..

·       Go into the super\awesome directory and move the Britney.txt file back to the Are directory by using:

 

         move britney.txt ..\..

 

STEP 9 – COPY OR MOVE UP A LEVEL AND IN ANOTHER DIRECTORY

 

·       Go to the directory awesome where you will find pink.txt.  You want to move it to the super\awesome directory.

To do this, we need to go up one directory back to Are, then go into super, then go into awesome.  So, we use:

    move pink.txt ..\super\awesome

STEP 10 – COPY OR MOVE TO AN ABSOLUTE PATH

 

·       Let’s copy pink.txt to the location C:\users\username where username is your actual username.  Try something like the following:

          copy pink.txt c:\users\campeap

 

Go check that it worked.

 

STEP 11 – TASK

 

·       Go ahead and move all artists into the folder that best describes them.  Make sure at least one is in super\awesome and in super\lame.

Feel free to create a few more text files representing other artists that you like.

 

STEP 12 – CONCEPT (LIMITATIONS OF COPY)

·       You can use move to relocate an entire directory tree.  However, the copy command can only be used to copy files (and not directories).  This is annoying!

This means that making a copy of a directory structure with files would be very painful using
copy.  You would have to manually make all the directories and then copy files from each directory to their copied version one directory at a time.  Yikes!

Thankfully, there is a command that can be used to copy all files in a folder:
xcopy.

 

STEP 13 – XCOPY

 

·       The command xcopy creates a copy of all the files in a directory.  However, by default, it does not copy the subdirectories.

 

·       Let’s make a copy of the Fun directory and call the new copy Fun2 by using:

 

                    xcopy Fun Fun2

 

Note that you do get asked if the destination (Fun2) is a file or directory.  It is a directory.

·       Take a minute to compare Fun and Fun2.  Notice that Fun2 contains the same files as Fun but none of the subdirectories.

STEP 14 – XCOPY /?

 

·       Check out all of the options that we have with xcopy by entering:

         
xcopy /?

 

STEP 15 – XCOPY /E

 

·       To copy all files but also all subdirectories and their files, we can use xcopy along with the /E.

Try the following:

 

                    xcopy /E Fun Fun3

 

·       Now go compare Fun and Fun3.  They should both be identical.

         

STEP 16 – ROBOCOPY /E

 

·       A more advanced copying command called robocopy had been created.  For basic jobs it works in the same way as xcopy.

Try the following:

     robocopy /E Fun Fun4

 

·       Again, because of /E, both Fun and Fun4 will be identical.

 

separator-blank.png