WINDOWS COMMAND PROMPT

LESSON – CREATING & DELETING FILES & FOLDERS

 

separator-blank.png

 

GROUP WORK

 

STEP 1 – 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 Lesson02Work directory which is inside the cmdWork directory.  This is where we will do our work for now.

 

STEP 2 – ECHO

 

·       We can display a message on the screen using the echo command.

·       Try this:

         
echo hello world

·       Try the echo command a few more times.

 

STEP 3 – CONCEPT (NO COMMAND TO CREATE A FILE)

 

·       In the command prompt, there is no command to simply create an empty file.  Most operating systems (including DOS) have a command named touch that allows you to simply create a file.

·       However, it is still very easy to create a file and we will look at that next.

STEP 4 – CONCEPT (REDIRECTING OUTPUT WITH THE > SYMBOL)

 

·       Start off by using dir to see the files and directories in your current folder.

·       The echo command usually displays a message on the screen.  However, we can use the > symbol to redirect the output to a file.

·       Try the following command:

         
echo hello > file.txt

·       Now use dir again.  Notice that file.txt has been created.

·       Use type file.txt to see the content of the file.

STEP 5 – CONCEPT (THE > SYMBOL OVERWRITES)

 

·       Try using the following:

         
echo bye > file.txt

·       Now try:

         
type file.txt

Notice that the file now contains
bye.  So the redirected echo call overwrote the previous content of the file.

STEP 6 – CONCEPT (ORDER OF OPERATIONS)

 

·       Try this:

     dir > test.txt

The above command has an unexpected result.  Windows actually creates the file test.txt first, before the dir command is executed.  So, you will actually see an empty (0 bytes) test.txt file in the result of the dir command.

STEP 7 – CONCEPT (APPENDING WITH THE >> SYMBOLS)

 

·       Try using the following:

         
echo see you later >> file.txt

·       Now try:

         
type file.txt

Notice that the message
see you later was added to the end of the file instead of replacing the previous text.

 

STEP 8 – MD

 

·       Go inside the Sesame directory using the cd command.

·       Use dir to see what is in the directory.

·       Create a directory named elmo by using:

         
md elmo

·       Use dir again to confirm that the directory was created.

 

STEP 9 – RD

 

·       We can use rd to remove a directory.  Let’s remove the directory bert by using:

         
rd bert

·       Check to make sure that the directory was removed.

STEP 10 – MORE ON RD

 

·       Try removing the directory named ernie. 

·       What happens?  (Hint: Big Bird is in the way!)

STEP 11 – DIR WITH RELATIVE PATH

 

·       We can check the content of the ernie directory without going into it by using:

         
dir ernie

So
dir can be used by specifying a relative path (a path that starts from your current location) to a new location.  More on this later.

 

STEP 12 – CONCEPT (EMPTYING A DIRECTORY)

·       Go inside the ernie directory and use rd to remove the bigbird directory.

·       Now go back out of the ernie directory and use rd to remove the ernie directory.

 

STEP 13 – DEL

 

·       Start by trying to remove the oscar directory.

This doesn’t work because its not empty.

·       Go inside the oscar directory and see what is there.

·       It contains the file jussayin.txt.

·       Because we are curious, let’s check what is in the file by using:

         
type jussayin.txt

·       Now we want to remove the file.  Do so by using:

         
del jussayin.txt

·       Go back up one level and remove the oscar directory.  Double check that it was removed.

STEP 14 – RD /S

 

·       Try removing the grover directory with rd.

It doesn’t work because
grover is not empty.

·       Take a look at what is inside the grover directory by using:

         
dir grover

·       We can remove grover and all of its content by using the /s switch with the rd command.  Try this:

         
rd /s grover

Of course, you can imagine that one has to be very careful with this command.  Otherwise, one may be reinstalling their OS shortly afterwards.

 

separator-blank.png