Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Python for File Systems!
You have completed Python for File Systems!
Preview
Once again, Python makes it easy to automate tasks. In this video let's take a look at how to search for files and directories.
Python Documentation
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
project files or favorite rock
operas together in one place.
0:00
Often, when we're creating software for
working with directories in files,
0:01
we wanna be able to search for
particular files and directories.
0:04
Luckily, Python makes this pretty easy for
us.
0:07
So I've imported os.
0:09
I'm gonna do os.listdir, and
you can see all of the files and
0:11
directories that are currently
in this directory.
0:15
Those dir method gives us back
everything that's in the directory.
0:18
By default,
it uses the current working directory,
0:22
but we can provide it a path
right here if you wanted to.
0:24
And it'll tell you everything
that's in that path.
0:27
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