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

Researching the Documentation

00:00 Okay, so I cleaned up the REPL a little bit just to give us more space over here. And before I want to actually get started, here’s another thought that I had.

00:11 I kind of, like, want to be able to test frequently and often. This was one of the tips that I wrote down also on the slide. And now I’m thinking, okay, so I have a practice_files/ folder that I want to do some operations on.

00:25 But once I move some files, the practice_folder/ is going to look different than before. So if I want to test often, but I do file system operations, I’m kind of changing the state of the folder structure that I’m interacting with, right?

00:39 So I’m thinking it might be a good idea to create a copy of that folder and then maybe first run my tests on the copy that I can just quickly discard and regenerate.

00:50 That would allow me to test more freely and more often, but still have the intact file structure to then run my final script on. Basically, if you went through the course, you might remember that deleting a folder recursively with content wasn’t possible with pathlib.

01:08 Now I’m wondering it might be a similar situation if I do want to copy a folder recursively with content in it. So what can I do? In this case, maybe I don’t exactly know what the right function is for that or even which module I should use, so I would head over to my search engine and just do a little bit of research and figure out if I can find a good solution for this task.

01:33 I might just go to my search bar and then think about what do I want to do. I want to copy a folder in Python, maybe pathlib, but it’s important that it’s recursively, and often, I like to go to the documentation.

01:50 So let’s see what I get here. And can I see anything? So I scroll a little to look for docs.python, and here I have again the shutil module that I’ve already used to recursively delete a folder. So that might be a good solution.

02:06 So in here, shutil. I did use .rmtree() before, delete an entire directory tree. So what about, let’s search for .copytree(). That seems to exist. There it is.

02:23 So we have shutil.copytree(). “Recursively copy an entire directory tree rooted at src to a directory named dst and return the destination directory.” Okay, that sounds quite familiar.

02:35 That looks similar to .rmtree(), and it seems to be helpful for what I’m trying to do here. So I’ll give this a go.

Become a Member to join the conversation.