at the moment i have a excel spreadsheet with a list of the current
images by product code (17153, 17154 etc) and i have to go through the
directory manually searching for each image associated with the product
( 17153.jpg, 17153a.jpg, 17153b.jpg, 17154.jpg etc)
I am wanting to create a script that goes through a excel file cell by
cell (column A) to then find the corresponding images (17153.jpg,
17153a.jpg, 17153b.jpg, etc) in a directory and then copy these image in
another directory
Step 1: Read the data from the spreadsheet. Try a gem like
“spreadsheet”, “roo”, or any of the other great ones which can handle
reading excel documents.
Step 2: Find the files. Look up Dir.glob or Ruby’s “Find”.
Step 3: Move the files. Look up Ruby’s File or Fileutils. There are
several options there.
You’re missing the wildcard from the search, which would defeat the
point of using glob, that case you might as well just specify the
filename directly.
Isn’t “row” an array? I’m not sure you can add the array to a string
like that. To debug, try breaking this down into smaller steps, each
with their own variable assignation and debugging output.
Compare the filename strings you’re picking up from the sheet to the
real filenames you have to check for differences.
I dont’ know how the spreadsheet data compares to the file itself, but
you could try something like
("/Users/eccleshall/ImageCleanUp/#{ row[0] }*")
That is: your directory path + the first cell of data in your row + a
wildcard to account for file extensions.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.