Reading a doc of image names then duplicating from/to folders

With the help of StefanK I was able to complete this script. I hope this helps whoever needs it.

Open this Scriplet in your Editor:


property thefolder : missing value
property newFolder : missing value
property SKUFile : missing value

--Select a image file folder.
if thefolder = missing value then set thefolder to choose folder with prompt "Select the folder with images."

--Select a folder to duplicate image to.
if newFolder = missing value then set newFolder to choose folder with prompt "Select the folder to move the images to."

--Select a text file.
if SKUFile = missing value then set SKUFile to (choose file with prompt "Select the text file with SKU list.")

set the_names to paragraphs of (read SKUFile)
set theCount to count the_names
set x to 0 -- error counter
repeat with this_name in the_names
   try
       tell application "Finder" to duplicate (1st file of thefolder whose name begins with this_name) to newFolder
   on error
       set x to x + 1
   end try
end repeat

set theMsg to "Script completed." & return
if theCount = 0 then
   set theMsg to theMsg & "No items were moved."
else if theCount = 1 then
   set theMsg to theMsg & "1 item was moved."
else if theCount > 1 then
   set theMsg to theMsg & theCount & " items were moved."
end if

display dialog theMsg & return & x & " error(s)" buttons {"OK"} default button "OK"