Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Can automator gather files listed in an excel spreadsheet?

Hi there,


We have a large catalogue of product images and are frequently sent Excel spreadsheets listing which images are required to be gathered and burnt to disc for a customer, for example.


Most of our image files are in folders by range and labelled with the item number ie 06897 (always 5 digits), but will quite often be within the filenames ie "HR 06897 Description.jpg".


Is there a way that we can use Automater to look at the item number column in Excel, search for the code in a filename within our 'Images' folder and copy the matching files into a new folder on the desktop?


It would then be even better if there was a way to output a report which showed which item codes it couldn't find so we can do the search manually.


Automator is so clever, but I'm not a clever driver of it so hoping that someone can help! This would save days of time, even if it could cut out half the searching!


Thanks,

Jenny

iMac, OS X Mavericks (10.9)

Posted on Nov 5, 2013 7:31 AM

Reply
66 replies

Oct 31, 2016 8:21 AM in response to NPatton

The way the script is written, it uses find with wildcards (so that if the excel file has "test", it will also copy files "test2", "test3", etc). find does not produce an error code if the file is not found, so there is no easy way to create an error report with find (perhaps someone else here knows how)


However, if you want to search for an exact match (and report an error if the file does not exist (in a file named "error.txt" on the Desktop) then

replace:

do shell script "find " & theDirectory & " -iname '" & theItem & "*' -exec cp {} " & theDestination & " \\;"

with:

try

do shell script "cp " & theDirectory & "/" & theItem & space & theDestination

on error

do shell script "echo " & theDirectory & "/" & theItem & " does not exist >> ~/Desktop/error.txt"

end try

Dec 1, 2016 2:31 PM in response to Tony T1

This works for me....


set theDirectory to quoted form of POSIX path of (choose folder with prompt "Select Search Directory")

set theDestination to quoted form of POSIX path of (choose folder with prompt "Select Directory to Copy Files")

tell application "Microsoft Excel"

tell active sheet

tell used range

set rc to count of rows

end tell

set theList to get value of range ("B1:B" & rc) as list

repeat with theItem in theList

if contents of theItem is not {""} then

do shell script "find " & theDirectory & " -iname '" & theItem & "*' -exec cp {} " & theDestination & " \\;"

end if

end repeat

end tell

end tell


But could you add back in...


do shell script "echo Files Not Found: > $HOME/Desktop/NotFound.txt"

thank you for your help.

Can automator gather files listed in an excel spreadsheet?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.