Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Performing a Folder Checkup

00:00 So let’s get started with this challenge. I’ve went ahead and downloaded the practice_files/ folder from the supporting material and placed it in my home folder for now, and it has the following structure. So it looks like this.

00:16 Over in my graphical user interface, you can see I have the practice_files/ folder here, and it contains all the things as shown in this tree structure.

00:28 So with this in place, I’m going to head over to IDLE. And here I have both an IDLE shell open on the left and then also a file because I want to write a script to achieve all these tasks.

00:42 So let’s start by taking a note of the task that I want to perform here. Copy this from the instruction. It says—going to have to make this a bit smaller—Create a new folder in the `practice_files/` folder called `images/`, and move all image files to that folder. This is basically the instructions that I want to tackle in this task.

01:07 I have the practice_files/ folder, and I’m going to just get started from there. I will use both the REPL here on the side to do some testing and basically some operations that are not really part of the final script, but that are going to help me to develop this program.

01:26 Let’s get started by doing a little checkup, whether the folder’s there and really contains what I expect it to. I’m going to import pathlib here,

01:37 or more precisely, I’m going to import the Path class from pathlib. Then we’ll start by creating a variable for the folder. So we just checked where it exists in the graphical user interface.

01:50 So let’s also go and check in here using pathlib. I’m going to say the practice_dir

01:59 is going to be Path.home() and then in here "practice_files"

02:11 Let’s double-check whether this folder exists. Oh, it does not exist. Did I make a mistake somewhere here? "practice_files". Path.home().

02:28 practice_dir. Let’s see. /Users/martin/practice_files. I thought this exists, so let me double-check. I am here in Users/ martin/python-basics-exercises/ and then practice_files/.

02:44 So I forgot that there is an extra folder in here. All right, good that I checked. So let’s repeat this

02:53 and add in here the missing folder that is called "python-basics-exercises", I think. Let’s double-check. practice_dir.exists().

03:15 Okay, so now I got the correct path of the directory, and I confirmed that it exists. You can say, like, it was good that I went ahead to check because I had forgotten that there is an additional folder in here, and I would’ve worked with the wrong path if I didn’t go ahead and check whether this is actually where the folder is located.

03:37 So, good takeaway. You can never check too often, basically.

Become a Member to join the conversation.