Web Programming Languages

Python: Directory Read

Read the contents of a directory of images. Exclude the non-image directory entries. Create a caption by deleting the file extension and capitalizing the file name.

The Python os.listdir function appears to show only the visible files, not the dot files, so we don't have to manually exclude the invisibles.

Choose a directory: ComicsEmbroideryCarvingTech

Marigold
Joyce
Sonny
Hannelore
Shauna
Dorothy
Claire
Dale
Walky
Lottie
Mildred
Dina

We can change the order of the files (for example, birth order instead of alphabetical order) by prepending each file name with a number and removing the number from the caption string.

Images courtesy of:
Stone Paperweight at World of Judaica
Embroidery Designs at 4-Hobby.com
Dumbing of Age
Scary Go Round
Questionable Content

Show Python source code »