Moving All Image Files to a New Directory (Challenge)
00:00 If you made it all the way through the review exercises, then I’ve got a challenge for you. I want you to use Python to move all image files into a new directory.
And start with a file and folder structure that you can download under Supporting Material from this course. There’ll be a ZIP file that you can unzip, and you will find a folder structure in there. There is a folder called
practice_files/ and then a subfolder called
documents/. Inside of that directory, there are several files and subfolders.
Some of the files are images that end with
.jpg file extensions.
Now what I want you to do is create a new folder in the
practice_files/ folder and call it
images/. And then you want to move all the image files to that folder.
That means all of the
.png, all the
.gif, and all the
.jpg files, but none others. So when you’re done, the new folder should have four files in it.
That’s going to be
image4.jpg. So, take on this challenge, try to practice using
pathlib some more, and build this little script that you can actually use to move image files from one location to another one.
And also create the
images/ directory using Python’s
pathlib. Just do everything with Python, basically. That’s the challenge for you to give you a nice little capstone for this course.
Thanks for flagging this @akazmierz. We’ll update the download later today so that you also get the folder structure together with the code files in the same ZIP file!
Become a Member to join the conversation.
akazimierz on Jan. 5, 2023
I got a problem: couldn’t find the zip archive with folders structure and files for the challenge – I checked this lesson (only archives with slides and code), checked at the very beginning of the course, and the end as well (I hope I didn’t make a mistake looking for the archive – if I did, please let me know.)