Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Video Player
00:00
00:00
00:00
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Let's cover some terminology that will be used in this course and an overview of where we're headed.
Treehouse Course
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Hi, I'm Kenneth.
0:04
And in this course I'm going to show you
how to use Python to take control of
0:06
the files and directories on a computer.
0:09
By the end of the course, you'll be able
to use Python to check the size of files,
0:11
create new files,
rename directories, and more.
0:14
Why would you want to use Python to do
tasks that you normally do with your
0:16
operating system's file explorer?
0:19
Occasionally, you'll find yourself working
on a system where you don't have any sort
0:21
of visual file explore, like looking on
a server or a microcontroller device.
0:24
Or maybe you have a repetitive
task like creating of files and
0:28
directory structure for a project.
0:30
And you're just sick and
tired of doing it by hand.
0:32
And even if none of that applies to you,
knowing more about Python and
0:34
how to use it for
tasks like this is never a bad thing.
0:37
This situations pop up when
you least expect them.
0:40
Before we get into the Python tools, and
libraries and code, I want to take a few
0:43
minutes to make sure your familiar with
the terms we'll be using in this course.
0:47
While I'm sure some of you
are comfortable with these terms,
0:50
it never hurts to have
a bit of a refresher.
0:52
Computers typically store data in files,
whether these are text documents, images,
0:55
movies or databases.
0:59
Files have two major parts,
their filename and their file type.
1:00
Most of the time, the file type is
reflected in the extension part of
1:04
the filename, which is the part that
comes after the dot in the filename.
1:06
For example, a very common image
format is the JPEG format.
1:10
Most JPEG files have
a .JPG file extension,
1:14
which tells you that it is a JPEG file.
1:17
The file extension, for
1:19
the most part though,
is just extra information for humans.
1:20
Computers and software would use the file
type, and not the extension to identify
1:23
what kind of file a file is, when it
needs to display or modify the file.
1:26
Files are stored in Directories.
1:31
It's become common parlance to
call directories folders, and
1:33
we usually have an icon of
a folder to indicate them.
1:36
But the actual name is directory.
1:38
I will do my best to stick to using
directory, but if I slip up, forgive me.
1:39
Directories often form a tree of sort,
1:43
with directories nested
inside of directories.
1:45
If I trace the directory tree
all the way back though,
1:48
I'll eventually come to the root
directory, or location.
1:51
On Windows,
this is usually a drive name, like C.
1:54
On a POSIX system, like Linux, Unix,
1:56
or Mac OS through, It would be just
a single slash that leans to the right.
1:58
I'll use backslash for slashes that
lean to the left like on Windows.
2:02
And forward slash, or just slash for
ones that lean to the right.
2:06
When we talk about the location
of a single directory or
2:10
file, we call this collection of
directory and file names its path.
2:12
For example, if I have a file named
my_next_course.py in my user's directory,
2:16
it might have a path like this,
C:\Users\Kenneth\my_next_course.py.
2:21
Actually, let's talk about those slashes
for a second, the official word for
2:28
them is separators.
2:31
On the Windows systems the slashes between
directory and file names lean to left,
2:32
every where else though
they lean to the right.
2:36
We call slashes that go
to the left blackslashes,
2:38
and those that go to the right
forwardslashes or just slashes.
2:40
If your typing out paths on these systems,
be sure to use the correct slash.
2:43
Python provides a system aware item
named SEP, S-E-P, in the OS module
2:47
to help you with this, but I'll show you
how you can avoid dealing with it at all.
2:52
In fact, we'll be using the OS library for
most of this course.
2:56
But like many Core Python modules
the OS module is huge, and
2:59
we won't be covering all of
it in just this one course.
3:03
If you're not comfortable moving
around in your file system,
3:06
check the teacher's notes for
a link to our Console Foundations course.
3:08
Otherwise, I think it's time to start
looking at the tools we'll use to prune
3:12
and grow our file tree.
3:14
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up