1
00:00:05,200 --> 00:00:09,520
In the previous video, we saw how to 
access files in the current directory. 

2
00:00:09,520 --> 00:00:13,861
Your first question is probably, "How do 
I know what is the current directory?". 

3
00:00:13,861 --> 00:00:18,814
Your operating system tries to help there.
Have a look at your operating system's prompt. 

4
00:00:18,814 --> 00:00:22,876
That's the text that appears, just 
before where you type your commands. 

5
00:00:22,960 --> 00:00:27,040
On Windows, the prompt ends with a 
greater-than symbol. Everything before 

6
00:00:27,040 --> 00:00:33,120
that is the full path to the current directory.
So my current directory is called Functions_Intro. 

7
00:00:33,120 --> 00:00:37,330
That's inside a directory called 
current-python-masterclass-remaster. 

8
00:00:37,330 --> 00:00:41,360
The current-python-masterclass-remaster 
directory is in the root of drive Y. 

9
00:00:41,360 --> 00:00:45,680
On your Windows computers, you should 
see the complete path in your prompt. 

10
00:00:45,680 --> 00:00:50,400
Note though, that the prompt can be 
changed. If you're using a company computer, 

11
00:00:50,400 --> 00:00:54,480
the prompt might be different.
Please don't ask how to change it. 

12
00:00:54,480 --> 00:00:58,160
A bit of googling will get you there, but 
if your company has changed the prompt, 

13
00:00:58,160 --> 00:01:00,800
then you may not be able to change it back. 

14
00:01:00,800 --> 00:01:03,600
So you can use the prompt to 
keep track of where you are. 

15
00:01:03,600 --> 00:01:08,327
On a Mac or Linux, the terminal prompt only 
shows the name of the current directory. 

16
00:01:08,400 --> 00:01:12,080
You don't get to see the full path.
It also abbreviates the name of your 

17
00:01:12,080 --> 00:01:16,762
home folder to ~, a tilde character.
If you lose track of where you are, 

18
00:01:16,762 --> 00:01:21,992
or just want to check, you can use the PWD 
command – short for Print Working Directory: 

19
00:01:24,320 --> 00:01:28,514
That's a useful command, to check the 
full path to the directory you're in. 

20
00:01:28,640 --> 00:01:32,400
On Windows, if you need to check, 
you can use the cd command, 

21
00:01:32,400 --> 00:01:35,239
without giving it a directory to change into: 

22
00:01:37,120 --> 00:01:41,120
That produces the same output 
as the terminal's PWD command. 

23
00:01:41,120 --> 00:01:44,720
Well, almost the same. There 
is a slight difference, 

24
00:01:44,720 --> 00:01:50,000
and this is the second difference between 
paths on Windows and paths on Linux or Mac. 

25
00:01:50,800 --> 00:01:55,840
Windows paths use the backslash character, 
to separate the various parts of the path. 

26
00:01:55,840 --> 00:02:01,520
We start with a drive letter, followed by a colon. 
That's optional, and if a path doesn't contain a 

27
00:02:01,520 --> 00:02:06,480
drive letter (followed by a colon) then it 
refers to something on the current drive. 

28
00:02:06,480 --> 00:02:10,639
After the drive letter, if 
there is one, we have a \. 

29
00:02:10,639 --> 00:02:16,898
Each of the directories, in the path, are 
separated from the previous one with a backslash. 

30
00:02:18,480 --> 00:02:22,640
The path above represents a 
file called course_notes.txt. 

31
00:02:22,640 --> 00:02:27,360
The file is in a folder called Documents, 
which is in a folder called timbuchalka. 

32
00:02:27,360 --> 00:02:33,835
The timbuchalka folder is inside a folder called 
Users, which is in the root folder on Drive C. 

33
00:02:35,360 --> 00:02:38,960
On Linux or Mac OS, the slash character is used. 

34
00:02:38,960 --> 00:02:41,920
This is what the path might 
look like on a Mac computer. 

35
00:02:41,920 --> 00:02:45,040
It will be very similar on a Linux 
machine; the main difference is 

36
00:02:45,040 --> 00:02:49,840
that users' home folders are usually in a 
directory called home, rather than Users. 

37
00:02:52,080 --> 00:02:56,240
The path above represents a 
file called course_notes.txt. 

38
00:02:56,240 --> 00:03:00,960
The file is in a folder called Documents, 
which is in a folder called timbuchalka. 

39
00:03:00,960 --> 00:03:06,630
The timbuchalka folder is inside a folder 
called Users, which is in the root folder. 

40
00:03:08,240 --> 00:03:11,280
I've used the term root folder 
in both of the last two slides, 

41
00:03:11,280 --> 00:03:16,720
so I should explain what the root directory is.
The root directory (or folder) is the top 

42
00:03:16,720 --> 00:03:21,680
level directory on a drive (in Windows). 
Each drive has its own root directory, 

43
00:03:21,680 --> 00:03:25,945
which is represented by the \ character.
So on a Windows computer, 

44
00:03:25,945 --> 00:03:30,640
you might have C:\ and Y:\
These represent the top level 

45
00:03:30,640 --> 00:03:36,640
directory on drive C and drive Y, respectively.
Linux and Mac don't use drive letters. 

46
00:03:36,640 --> 00:03:40,000
That means there's only one root 
directory for the whole file system. 

47
00:03:40,000 --> 00:03:44,926
On those operating systems, the root 
directory is represented by a slash /. 

48
00:03:47,040 --> 00:03:52,594
I'll demonstrate using the root directory shortly.
First, there's one more thing you need to know about – 

49
00:03:52,594 --> 00:03:56,160
absolute and relative paths.
An absolute path will get you to your 

50
00:03:56,160 --> 00:04:00,640
destination, no matter where you start from.
A relative path will get you there from where 

51
00:04:00,640 --> 00:04:05,895
you are now. If you use it from somewhere 
else, you won't get where you want to be. 

52
00:04:07,760 --> 00:04:13,360
We use relative paths often, in everyday life.
You might be trying to find a particular shop, 

53
00:04:13,360 --> 00:04:18,640
in a strange city. You ask for directions, 
and might be told something like: 

54
00:04:18,640 --> 00:04:23,040
"Take the next left, turn right at the 
church, and it's straight in front of you". 

55
00:04:23,040 --> 00:04:27,520
Those directions will only work from where 
you are. The path from your current location, 

56
00:04:27,520 --> 00:04:31,803
to the shop, is relative to your current location. 

57
00:04:33,280 --> 00:04:38,240
If I was already in my home directory, and 
wanted to find that course_notes.txt file, 

58
00:04:38,240 --> 00:04:43,680
I can use the relative path:
Documents\course_notes.txt 

59
00:04:43,680 --> 00:04:49,095
or Documents/course_notes.txt, in a terminal. 

60
00:04:50,400 --> 00:04:54,880
When working with relative paths, there 
are two useful shortcuts you can use. 

61
00:04:54,880 --> 00:05:00,400
A dot, or period, refers to the current directory. 
That's not something that Windows users will need 

62
00:05:00,400 --> 00:05:06,640
very often, but it can be useful on Linux or Mac.
On those operating systems, you use dot slash, 

63
00:05:06,640 --> 00:05:10,560
to tell the operating system to execute 
a file in the current directory. 

64
00:05:10,560 --> 00:05:14,960
That's all I'm going to say about dot.
dot dot – two periods – refers 

65
00:05:14,960 --> 00:05:21,208
to the directory above the current one.
We'll see an example of that, after these slides. 

66
00:05:22,960 --> 00:05:27,680
An absolute path specifies the location of a 
resource regardless of where you start from. 

67
00:05:27,680 --> 00:05:33,360
The most common use of absolute paths, in 
everyday life, is probably internet URLs. 

68
00:05:33,360 --> 00:05:38,240
We have to provide the name of the server we 
want to connect to – for example python.org. 

69
00:05:38,240 --> 00:05:42,560
We then provide the name of a page – 
possibly with some directories before it. 

70
00:05:42,560 --> 00:05:45,137
For example, and I'll switch to my browser,

71
00:05:45,468 --> 00:05:47,167
I can type 

72
00:05:50,400 --> 00:05:54,867
into the address bar, and we'll get 
to the page for downloading Python. 

73
00:05:56,720 --> 00:06:00,640
Note that the internet is 
Unix based. So we use slashes, 

74
00:06:00,640 --> 00:06:04,800
not backslashes, in the paths.
Wherever we are in the world, 

75
00:06:04,800 --> 00:06:10,455
that path provides the absolute location 
of that page, on the python.org server. 

76
00:06:11,280 --> 00:06:16,136
The original examples I used, in 
these slides, were absolute paths. 

77
00:06:16,136 --> 00:06:19,040
The path below
will find the course notes file, 

78
00:06:19,040 --> 00:06:23,198
no matter which drive I'm on, or 
which directory I happen to be in. 

79
00:06:24,400 --> 00:06:28,560
Ok, let's see some examples of 
using absolute and relative paths. 

80
00:06:28,560 --> 00:06:32,800
I'm on Drive Y, in the folder 
for the Functions_Intro project. 

81
00:06:32,800 --> 00:06:37,040
I can check which other project directories I 
have, by providing the full path to my course 

82
00:06:37,040 --> 00:06:40,416
remaster directory.
That would be 

83
00:06:47,440 --> 00:06:51,120
That uses the absolute path, 
and it's a lot of typing. 

84
00:06:51,120 --> 00:06:54,800
Because I'm already on Drive 
Y, I can shorten that slightly. 

85
00:06:54,800 --> 00:06:58,136
There's no need to specify the 
drive letter of the drive you're on: 

86
00:07:04,960 --> 00:07:09,680
We get the same results.
This time, the path is relative. 

87
00:07:09,680 --> 00:07:14,400
It doesn't specify the drive letter, so 
it only works from a location on Drive Y. 

88
00:07:14,400 --> 00:07:20,425
In a terminal, the path would be absolute. Linux 
and Mac operating systems don't use drive letters, 

89
00:07:20,425 --> 00:07:25,514
so the slash at the start of the path would 
mean an absolute path, from the root directory. 

90
00:07:25,514 --> 00:07:28,160
What if I wanted to check 
what was in my home folder? 

91
00:07:28,160 --> 00:07:31,611
I'm on Drive Y, so I have 
to provide the drive letter: 

92
00:07:36,960 --> 00:07:41,680
Once again, that's an absolute path.
But if you remember, I was in my home 

93
00:07:41,680 --> 00:07:45,663
directory before I switched to drive Y.
The system knows that, 

94
00:07:45,663 --> 00:07:48,957
so I only need to provide the drive letter (with a colon):

95
00:07:52,347 --> 00:07:57,439
Once again, we get the same listing – all the files and directories in my home folder.

96
00:07:57,439 --> 00:08:03,489
Note that I didn't use a backslash there. 
If I had, we'd get a directory of the root of the C drive: 

97
00:08:08,240 --> 00:08:12,800
Alright, I'm going to stop using drive letters 
now. We'll pretend that I only have one drive on 

98
00:08:12,800 --> 00:08:17,680
this computer, and work just with Drive Y.
For Linux and Mac users, everything we've 

99
00:08:17,680 --> 00:08:22,640
covered so far, with the exception of 
drive letters, also applies in a terminal. 

100
00:08:22,640 --> 00:08:25,656
Let's check what files are 
in my HelloWorld folder. 

101
00:08:25,656 --> 00:08:28,351
I can use an absolute path:

102
00:08:37,001 --> 00:08:41,945
Remember that's not really absolute, on Windows, unless you only have a single drive.

103
00:08:41,945 --> 00:08:44,819
Once again, that's a lot to type.

104
00:08:44,819 --> 00:08:50,720
I can use a relative path, from my current folder.
To do that, we need to go back one level, 

105
00:08:50,720 --> 00:08:56,216
then go forwards to the HelloWorld directory. 
We can use .. (dot dot) to do that: 

106
00:09:01,120 --> 00:09:07,539
The same thing works in a terminal. I just have to 
remember to use a slash, rather than a backslash: 

107
00:09:12,720 --> 00:09:17,200
Dot dot is very useful, when you want to go 
back one level from your current directory. 

108
00:09:17,200 --> 00:09:22,189
You can chain dot dot, if you want to go 
back more than one level. For example: 

109
00:09:27,200 --> 00:09:31,009
Or, if you're using a Windows command 
prompt rather than a terminal: 

110
00:09:34,880 --> 00:09:39,520
will produce a directory listing of the root.
You probably won't use that very often – going 

111
00:09:39,520 --> 00:09:44,320
back one level is usually all you want to do.
Alright, I'll finish this brief discussion about 

112
00:09:44,320 --> 00:09:49,112
file paths with a third difference 
between Windows, and Mac or Linux. 

113
00:09:50,160 --> 00:09:55,676
The title of this slide says it all. On 
Windows, filenames aren't case sensitive. 

114
00:09:55,676 --> 00:09:58,960
HelloWorld.py refers to the 
same file as helloworld.py 

115
00:09:58,960 --> 00:10:06,160
(or any mix of case, eg. hElLowoRlD.PY).
On Linux, file names are always case-sensitive. 

116
00:10:06,160 --> 00:10:09,840
The 3 names I've just used 
would refer to 3 separate files. 

117
00:10:09,840 --> 00:10:13,120
That's a common source of problems, 
especially for people moving from 

118
00:10:13,120 --> 00:10:20,960
Windows to one of the other operating systems.
On Mac OS, by default, file names are not 

119
00:10:20,960 --> 00:10:26,640
case-sensitive. But they are case-preserving.
You can't create those 3 files in the same 

120
00:10:26,640 --> 00:10:31,360
directory, because the names would clash.
If you attempted to, you'd end up with 

121
00:10:31,360 --> 00:10:35,920
just the contents of the last one – but 
preserving the case of the first filename. 

122
00:10:35,920 --> 00:10:41,280
That can be very confusing!
As a guide, treat all filenames as case-sensitive. 

123
00:10:41,280 --> 00:10:43,920
Your code will then work on 
all three operating systems, 

124
00:10:43,920 --> 00:10:48,240
and you won't wonder why you can't 
find a file that you're sure exists. 

125
00:10:50,000 --> 00:10:53,680
These few videos have been a 
quick introduction to file paths. 

126
00:10:53,680 --> 00:10:56,580
Experiment with the directories 
on your own computer. 

127
00:10:56,580 --> 00:10:59,680
You may want to browse some files in your 
operating system's file manager, 

128
00:10:59,680 --> 00:11:04,093
then try to do the same thing from 
the command prompt, or terminal. 

129
00:11:05,840 --> 00:11:09,200
If all this is new to you, you'll want 
to learn more about your filesystem, 

130
00:11:09,200 --> 00:11:12,160
and using the command line.
Here are some suggestions 

131
00:11:12,160 --> 00:11:17,920
for things to google, to find out more:
File names and paths on <windows/linux/mac> 

132
00:11:17,920 --> 00:11:22,400
Using the Windows command prompt
Using the <linux/mac> terminal 

133
00:11:22,400 --> 00:11:25,260
Command line completion 

134
00:11:26,800 --> 00:11:29,920
Getting comfortable with file 
paths, and the command line, 

135
00:11:29,920 --> 00:11:34,960
will make your life as a programmer much easier.
It's especially important when working with files, 

136
00:11:34,960 --> 00:11:38,428
which is what we'll be doing 
for the rest of this section. 

137
00:11:39,120 --> 00:11:41,840
I'll see you in the next video.

