Writing Code to Move Files
00:00 Okay, so that worked nicely. Let’s bring this functionality over into the script. For that, I’m just going to go ahead and copy what I wrote here—it was working well, after all—and I’m going to paste it here into the script.
Now, maybe let’s actually look at the names of the files, not just the suffix, and see whether this still works. So it’s going to look into
copy_dir/ and look for these three file types and print out the name of the files. So I will go ahead and press F5
And that’s the next step. Now, instead of just printing out their names, I want to move them. You learned about the
.replace() method that you can use on a
Path object to move it from a source to a destination. I do have access to the source here, so this path is going to be the path of the four files that I want to move.
And now I also need a destination. So I have source of file to move and then I also need the destination. How do I get the destination? I already know that I want to put them inside of the
images/ folder, and I have access to that path, or just the
Become a Member to join the conversation.