Hi once again. My head is getting flat from hitting the wall trying to figure this out.
What I need to do is take a text document that has images listed on it and locate then in a folder then duplicate them to a different folder. Resulting in 2 copies of the image files. Then I need a count of the transaction to verify the counts jive. This has to be variable for the documents and folder destinations because I would have different text documents and different folders in our process. If I’m making sense.
2nd try to explain. My list of image names are generated from Microsoft Access (ex: 12345 345870 8754 9029635412. The file names are not consistant in the number of characters. Images are supplied in a folder to us as ( ex: 12345_A.eps, 345870_A_v1.eps, 8754_A_v3.eps, 9029635412_A.eps)> Not exactly consistant either.
So what I have so far is this:
property thefolder : missing value
property newFolder : missing value
property specsFile : missing value
if thefolder = missing value then set thefolder to choose folder with prompt "Select the folder with images."
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 specsFile = missing value then set specsFile to (choose file with prompt "Select the text file with specifications.")
set thisfile to read file (specsFile as string) using delimiter {return}
tell application "Finder" to set theFiles to (get files of thisfile)
set theCount to count theFiles
set x to 0 -- error counter
set POSIX_newFolder to POSIX path of newFolder
repeat with eachFile in theFiles
tell application "Finder" to set fName to name of eachFile
try
set the destination_path to the quoted form of ¬
(destination_directory & (name of the item_info))
do shell script ("/usr/bin/ditto -rsrc " & item_path & " " & destination_path)
--comment out if you don't want to delete files
do shell script ("rm " & item_path)
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"
Now I realize the shell script is incorrect but I can’t seem to find a correct example of duplicating the files. Am I close? Any help would be appreciated. Thanks in advance.
Mike
Well, while waiting for some help, I’ve given it a second shot.
To recap:
What I need to do is take a text document that has images listed on it and locate them in a folder. Then duplicate the images to a different folder. Resulting in 2 copies of the image files. Then I need a count of the transaction to verify that the counts jive. This has to be variable for the documents and folder destinations because I would have different text documents and different folders in our process. If I’m making sense.
2nd try to explain. My list of image names are generated from Microsoft Access (ex: 12345 345870 8754 9029635412. The file names are not consistant in the number of characters. Images are supplied in a folder to us as ( ex: 12345_A.eps, 345870_A_v1.eps, 8754_A_v3.eps, 9029635412_A.eps)> Not exactly consistant either.
So what I have so far is this:
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 thisfile to read file (SKUFile as string) using delimiter {return}
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
duplicate 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"
Can’t say this one is much better. I get errors on all images, no duplicating but it gives the right count. I guess that is something. Any suggestions?
Thanks in advance
Mike
sorry, this is quite confusing, (but not as confusing as the first example ;))
In which folder(s) are the source files?
The main error is, you can’t move or duplicate a file name, you need to specify the full path to the (existing) file
If the file names differ from the read data, you have also to compose the real file name
Thanks for replying;
Hopefully I can be clearer this time.
The source files would be in “theFolder”. We could call it “SourceFolder” if that is clearer.
Sorry, I guessed by establishing a path to the “theFolder” with the prompt, which contained the source file images, that was accomplished. I have to hard code the path?
Considering there are several hundred image names and actual images to sort through, I was hoping there was a way to match just the front section of the file names. Are you saying they have to match exactly?
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"
Hey folks. Me again. I thought I had the problem licked thanks to StefanK. However, it requires a little tweeking. The main problem I’m having is it consistantly picks up images that are not on the SKUFile (text file) being read. In first SKUFile there is one wrong image which is the first image being duplicated. A second SKUFile being used drops 6 images and replaces them with images not on the list. I thought resetting the variable information would do the trick, but no luck. Any ideas? Do you need an example of the text file?
Here is the script I have to this point.
property thefolder : missing value
property newFolder : missing value
property SKUFile : missing value
property this_name : missing value
property the_names : missing value
property theCount : 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"
--Reset information
set thefolder to missing value
set newFolder to missing value
set SKUFile to missing value
set this_name to missing value
set the_names to missing value
set theCount to missing value