Join Barron Stone for an in-depth discussion in this video Creating directories and relocating files, part of Code Clinic: Python (2014).
- In this final video, I'll show you how I created the…new directory to put the sorted images into…and how I copy remove those images using the shutils module.…Continuing from where we left off in the previous video,…I use a for loop to cycle through each of the keys…in my dictionary of path lists.…Those keys of course, are the letters of the alphabet.…For each key, I check to see if any images had been found…with captions beginning with that letter…by indexing that key and checking to see…if there are any contents in that list.…If I do have images to put in the sort directory…for that letter, then I generate a path to…the sort directory by using the OS modules…path.join function to appin the key…to the users specified destination directory.…
After that I use the path exists function…to check if a folder with that path name,…already exists in the file system.…If it does not, then I'll need to create it…and I do it by passing that path to the make_dirs function.…I put the make_dirs function inside of a try except block…
Barron introduce challenges and provides an overview of his solutions in Python. Challenges include topics such as statistical analysis, searching directories for images, and accessing peripheral devices.
Visit other courses in the series to see how to solve the exact same challenges in languages like C#, C++, Java, PHP, and Ruby.
Skill Level Intermediate
Q: Why can't I access the Lake Pend Orielle site (http://lpo.dt.navy.mil)?
A: The Lake Pend Orielle site is not accessible in some geographical areas. We have contacted the owner of the server to try to resolve this issue.
Q: I am unable to access the Lake Pend Oreille data from outside the U.S.
A: A static copy of this data is provided here for lynda.com members outside of the U.S