-1

I need ruby code where i can loop throught a list of folders and then loop through each image individually in that folder

List of folders

by grabing the pictures file and its name,

I know Dir.foreach is great to get the folder names but how do I get the pictures

BobTheCat
  • 107
  • 2
  • 2
  • 7

2 Answers2

1

If I understand you correctly, you want a list of each file if it's an image?

If your images are all the same format, IE .jpg, you could use:

folder_results = Dir.foreach("your_folder_name") {|x| File.extname(x) }

for file in folder_results
    if (file === '.jpg')
    # do something
    end
end
James Stewart
  • 669
  • 7
  • 24
1

If you run following code from the base directory of your file structure, then it will list all files ending in ".jpg" or ".png".

Dir.glob("./**/*.{jpg,png}").each do |file|
  puts file
end
Pascal
  • 7,781
  • 1
  • 19
  • 28