Web Programming Languages

Ruby: 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 Ruby Dir function lets you specify exactly the files you want included in the list, such as Dir["../birth/*.png"]. So, there was no need to manually exclude invisible files, dot files, or directories.

Choose a directory: ComicsEmbroideryCarvingTech

Judah
Asher
Benjamin
Gad
Reuben
Joseph
Dan
Zebulun
Simeon
Naphtali
Issachar
Levi

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 Ruby source code »