Author Topic: Collect images from a folder  (Read 1844 times)

0 Members and 1 Guest are viewing this topic.

Offline dener11

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Collect images from a folder
« on: June 30, 2010, 02:18:28 PM »
I have an excel file that has 8000 image names that I would like to have a script search a selected folder (with sub-folders) and copy the image from the list to a new folder. Any ideas if this is possible?

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Collect images from a folder
« Reply #1 on: July 01, 2010, 02:40:17 AM »
This is actually fairly simple, providing your excel doc is nicely made. (e.g. no sub headers, no gaps in the data).
The following script should get you going and will work assuming your excel file is open, the image list is in column A and has no header.
You will get problems if your destination folder is inside the search structure. You may have to do something if your images are in the list > once.
As a bonus it will put the original path in column B if the image is found.

Code: [Select]
set theFolder to choose folder with prompt "Set the Search Location"
set theSearchPath to POSIX path of theFolder
set theDestination to choose folder with prompt "Set the Required Destination"
set theDestination to POSIX path of theDestination

tell application "Microsoft Excel"
set rownum to 1
repeat
set theName to (value of cell 1 of row rownum) as string
if theName = "" then
exit repeat
end if
set thePath to ""
set thePath to do shell script "find '" & theSearchPath & "' -name '" & theName & "'"
if thePath = "" then
set thePath to "not found"
else
do shell script "cp '" & thePath & "' '" & theDestination & "'"
end if
set value of cell 2 of row rownum to thePath
set rownum to rownum + 1
end repeat
end tell

Offline dener11

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Collect images from a folder
« Reply #2 on: July 01, 2010, 02:06:40 PM »
Works great but for some reason I have some image names that are the same. Can we set it up on an error to skip the item and move to the next name on the list.

Thanks

Dener11

Offline cdms

  • Full Member
  • ***
  • Posts: 111
  • Karma: 6
  • Gender: Male
Re: Collect images from a folder
« Reply #3 on: July 05, 2010, 02:17:30 AM »
Put

try

end try

around the do shell script "cp .... line

Offline dener11

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: Collect images from a folder
« Reply #4 on: January 04, 2011, 12:30:29 PM »
This script works great but I am having issues now with it finding duplicates. Can we ask for the script to copy the most current image files?