 Before we can do any scripting, you have to learn how to use the command line and how files and directories, they're also called folders on Windows, are organized on your computer. Therefore we'll start with a tutorial on using the command line. After this tutorial you'll be able to use the command prompt and the most common commands, navigate to files and directories and use their relative and absolute paths, and make batch files. During the exercises we're going to use the command prompt. In this demonstration we'll use the online DOS emulator. But you can also use your own command prompt on your computer. So what we see here on the screen is the command prompt. It shows your current working directory. In this case it means that you are at the C drive, which is also called the root of the drive. You cannot delete or edit the command prompt. You have to type the commands after the larger than. Let's type our first command, DOS key, and we type always enter after the command to execute the command. In this case we activated the logging of the command history, which we'll use later. We will view the contents of the directory by using the dir command. The dir command stands for directory. Here we see the listing of the directory. The directory list is a list of all the files and subdirectories that the directory contains. If you type dir slash question mark, you will see all options of the dir command. For example, if you type dir slash w, you will see the directory listing in columns. And you see the subdirectories in square brackets. We can also change the drives. If you have different hard drives or partitions, you may need to change to another drive. If you are on drive C and you want to move to drive D, you can type D column, enter. And then you will move to drive D. In this case we get an error because we don't have a D drive. If you do have another drive, it is recommended not to use the drive C, because it contains your system files. In these exercises in the online DOS emulator we will use the C drive, because it doesn't have other drives. Here we did another listing and we see that the directories have dir beside them. The others are files. The size of the files are also displayed. You can see a list of the files in another directory by changing to that directory and then using the dir command again. Let's use the md command to make directories. With md john we make a directory john and with md peter we make a directory peter. So we have created two subdirectories under the root C. Let's do the dir command to see if this happened. And there we see the two subdirectories have been created. We can also use the dir slash ad command. This will show us all the subdirectories under the root C and not the files. Now to move to another directory we can use the cd command which means change directory. So if we want to go to john we type cd john and we press enter. And then we are in john. Note that DOS is not case sensitive. It interprets upper and lower case in a similar way. Other operating systems are case sensitive. And also if you do programming the case is important. Now we can list the contents of john by typing dir as we did before. We would expect an empty directory but we see two files. A dot and dot dot. These are relative paths. One dot means current directory. Two dots means mother directory or one directory up. Let's type cd dot dot. And we see where we are, we are at the root so we went one up. Let's type cd dot. This means change directory to here and we stay at here. Let's look a bit further at this. Let's go to the directory john using these relative paths. So I can type cd dot slash john. Enter. This means move from here to john. I can do again cd dot dot to move back to the root. These are relative paths. In a similar way I can use absolute paths which are always absolute to the start of the drive. In this case c. So I can type cd c colon backslash john. This is changing the directory with the absolute path from the root of the drive to john. I can also go back to c in an absolute way by using the backslash. The backslash means root. Let's go back to the directory john. You can use either a relative or an absolute path for that. Here I simply type cd john. Now I want to go to peter in a relative way so I do cd one up so dot dot backslash peter enter. Now I am in peter in a relative way. I went one up and then I went to peter. Both ways of changing directories are equivalent. Why bother them? Well, if you move your files that are organized in directories and subdirectories to another drive, for example drive d, then your absolute paths will not work, while your relative paths will still refer to the same locations. This is specifically important when writing scripts, which we'll do later. Now we're going to delete directory so I go one up. So I'm back in the root and I can use the rd command, remove directory and I type rd peter enter and then the directories removed. Let's use the dir command to verify if it happened. And yes, we can't see the peter subdirectories anymore. Note that in this way we can only remove empty subdirectories. We can also create files. Of course you can create files using your Windows software, but since you're learning the command prompt, you will learn how to create a simple ASCII file from the command prompt. In this case we use the copycon command, which means copy to console. So let's type copycon listdir.bat, that will be our new file that we create and we press enter. Then we can type the text that we want in our file. Here we're going to type dir slash ad. You see that at the beginning of the line there is no prompt. So this is not a command, but this is text because we're inside listdir.bat. We can add more lines, but here we're going to close the file by typing control z. So we keep control pushed and we type z and then it saves the file. Now let's do a directory listing and check the file. And we see listdir.bat has been added and it's 9 bytes. We can also display the contents of the file on the screen. Therefore we use the type command. So we type type listdir.bat and we press enter. And it will show us the content of the file. I can also just type listdir and press enter. And here it will execute the file. It shows us now the directory listing and only the subdirectories in the list. So we have created our first script. It's a batch file. Batch files are scripts that can be used to execute commands in batch. In this case the file executed dir slash ad. Because batch files always have a file extension dot bat the computer knows that this is a batch file and will execute the commands in the file. We'll come back to this later. Let's create another file. We type dir larger than list dot text and press enter. The command will not show the results of the dir command on the screen but saves it to an ASCII file, a text file called list dot text. So we can use larger than after command to save its results to a file instead of printing it to a screen. Let's check the contents of the file. Again we can use the type command. Type list dot text. And we press enter and there we see the contents of list dot text. You can see that the list is larger than your screen. We can use a special command to look at different pages of a file. We can use type list dot text and then the pipe symbol and then the more command. And we press enter. And now we see the list nicely on the screen with more and if we press enter we can see the next page. You can also use control C to stop listing the pages for very long documents it might not be needed. So the more command controls that we can see it in different pages and you can use it for everything that needs to be reported to the screen. So let's use the more command standalone and nothing will happen. If you want to stop this we use control C. So with control C we can stop anything that is hanging. Now let's try something else. We're going to type type list there dot bot so listing of our files and then larger than larger than list dot text. And we press enter. Let's see what happened by looking at the contents of list dot text. And we also use the more command. What we see here is that list there dot bot is appended to list dot text. So what we've learned here is that with larger than we can save the result of a command to a new file. If the file on the right hand side of larger than already exists it will be overwritten. Larger than larger than appends the results of a command to an existing ASCII file. The pipe symbol uses the result of a command on the left hand side in the command on the right hand side of the pipe symbol. And with control C or control break we can stop the execution of a command. We can also use these operators to create so called log files. These are used in scripting. The script will check if a certain file exists. If it exists the program will wait. If it is removed the program continues. Therefore these files can be empty. You can easily create these log files by typing type null larger than log file dot text. Well null means nothing written to log file dot text. If we do a directory listing we find log file dot text with 0 bytes. So this is an easy way to make a log file which has no contents. You can also copy, move, rename and delete files. Let's first look at copying files. We can copy the list dot text file to a new file by typing copy list dot text new list dot text and press enter. Let's see if it has been added by doing the deer command. And here we see that new list dot text has been added. We can append text files also with the copy command. Then we type copy list dot text plus new list dot text and then the output file name list append dot text and we press enter. Let's check the contents of this new file. Type list append dot text. And there we see indeed that it has been appended. We can also copy list dot text to a subdirectory. So let's copy it to the subdirectory john. We type copy list dot text and then to the destination we leave a space john backslash new list to dot text which will be the output file name. And then we press enter. So this is a way to copy list dot text to the subdirectory john with new name new list to dot text. So let's go to john and see if that happened. See the john to go to john and there to list the files and there we see that it has been added. We can also move and rename files. Now we're going to move new list dot text to the directory john. So let's go back to the root. CD backslash brings us back to the C drive. And we type move new list dot text space john and we press enter. Now it indicates that new list dot text has been moved to the subdirectory john and the file new list dot text. If we go to john and we list the directory we see indeed that it has been moved. Because it is a bit confusing to have a copy of new list dot text in the subdirectory john we're going to rename it. We use the rename command. Rename new list dot text and we call it list john dot text. And we press enter. Let's check if that happened by listing the directory and there we see it happened. Now let's save the directory listing to a file called dirjohn dot LST. So we use dir larger than dirjohn dot LST. And let's check the contents. Type dirjohn dot LST. And there it is. We can also use wildcards. So let's make a directory listing and we're going to try a few wildcards. We have the star and we have the question mark. If I do dir star dot txt it will only list the txt files. So with star it can be anything that is replacing the star. I can also do dir star dot question mark question mark t. Then it will give me all the files that have this pattern of any character dot character character t. Let's do that a bit more specific. dir star dot question mark xt that will give me only the files that end on xt. So that's how the wildcards work. We can also delete files. Because we made copies we want to remove duplicate files. We will first remove new list 2. We use the del command to remove files. New list 2 dot txt. And if I do a directory listing I can see it's removed. Make sure you're in the right folder. There's no undo and it doesn't go to the trash folder so you can't recover it anymore. So it's unlike removing it from File Explorer in Windows. Now let's remove everything here in the folder. I can use del star dot star but also simply del dot. When I press enter it warns me that everything will be deleted. If I'm sure I type y for yes and press enter. And I see that everything has been removed and you can't recover it again. Now I'm also going to remove the john sub directory. So I go one up and I use the rd remove directory command. Remove directory john. Remember that we have turned on doski that is for logging the command line history. Sometimes you often use the same command. There are several tricks to type them more efficiently. In your windows command prompt doski is by default activated. Doski is the tool that tracks the command line history. The emulator that we are using here has some limitations and some of the commands in this part might not work. Let's test if it remembers the commands. We can use the F3 button. If I type F3 I see the last command that I used printed on the screen rd john. We can clear the command prompt and use the right arrow button several times. We see that we can get separate characters back of the last command. I can also use the up and down buttons which I can use to browse through the recently used command list. When you use tap while typing a part or a file name it will automatically complete it. This is very useful because you avoid typos. In the emulator this doesn't work but in your own command prompt you can use it. So don't type the complete file and directory names but use tap completion to avoid typos. There's some more things we can do with the doski command. Let's type doski slash h. This will give me the full history since I've started this session. If you close the command prompt this history will be lost. But we can also save this to a text file. We have learned that before. We can use doski slash h and then use larger than and we can save it to a file. Let's call it log.text. In that way we create a text file that has the log of all the commands. Let's look at it and we use the more command to separate it over pages. There we see all the commands that we have been using. We can also use this to create batch files. We can rename the log file to log.but and then we can execute the commands in batch. You can close the command prompt by either clicking on the cross in the corner typing exit and pressing enter or choosing close when right clicking the command prompt icon in the taskbar. For the emulator we can simply close it by closing the browser tab.