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.

Doing a Final Test Run

00:00 So I did a bit of refactoring in the previous lesson, so it’s a good idea to run the script again, test it out whether it still works the same way it did before. So for that, I’m going to start by deleting the copy_dir/ that we have from before and re-creating it so that I can run it another time.

00:19 So over here in the IDLE Shell, I’m just going to import shutil and also pathlib’s Path class.

00:32 And then I want to define the path to copy_dir/. I’ll copy this. copy_dir

00:50 and then I can use shutil.rmtree() to delete the copy directory.

01:02 Okay. Got rid of it. And now I will re-create it from the practice_files/ directory. So we’ll also need the path to practice_files/.

01:13 source is going to be copy_dir.parent and then "practice_files". I’m going to copy it now so that I don’t type it wrong.

01:28 And I can say shutil.copytree(), and I want to copy source and into the same path where copy_dir was before. I get it returned, and it means I have a new copy directory, and it doesn’t yet have the images/ folder.

01:48 Perfect. That puts me into the position to run this once again. So I’ll go over here and do the final test run after refactoring the script, I will press F5 and run it one more time on copy_dir/.

02:07 Let me see. We got an images/ folder, and all the images are here, so it seems like the script still works as expected, which is great. Okay, let’s do a final cleanup. Get rid of copy_dir/. We’ll have to import again. It’s all about training, right?

02:27 Define the path …

02:30 and remove it.

02:36 Goodbye, copy_dir/. And that also means that I will delete this line of code, and we will finally swap over to use the "practice_files" directory.

02:50 What I want to do now, though, is I will actually get rid of DIRECTORY and put this name of the folder again at the end of the path. The reason for doing this, it’s not ideal here because you’re not going to be able to see what is the folder name that you’re working with.

03:09 It goes a little bit too far to the right, but there is an advantage to it. And let’s discuss that and just do another quick roundup on the final script in the next lesson.

Become a Member to join the conversation.