with timeout of 600 seconds
--GET TEXT DOC INTO LIST FORM FOR COMPARISON TO FOLDER FILES
set aFile to (choose file with prompt "Select a file to read:" without invisibles)
open for access aFile
set txt to (read aFile)
close access aFile
set mylist_1 to {}
set para to paragraphs of txt
--Copy Text file to new list
repeat with aP in para
if (count aP) ≠0 then copy aP to end of mylist_1
end repeat
---------------------------------------------------------------
-- SET FOLDERS
set myfolder to choose folder with prompt "IMAGE FILES?"
set dstfolder to choose folder with prompt "DESTINATION FOLDER?"
---------------------------------------------------------------
--START PROCESS
tell application "Finder"
set myfiles to every file of folder myfolder whose name does not start with "." and (file type is in {"TIFF", "JPEG"} or name extension is in {"tiff", "tif", "jpeg", "jpg"})
repeat with i from 1 to number of items in myfiles
set thename to (item i of mylist_1 as string)
duplicate file named thename of myfolder to dstfolder
--display dialog thename (if I uncomment this works)
end repeat
end tell
end timeout
**The Problem
Totally Confused! I have this script posted below. I target a .txt file which contains paragraphs of various file names like this:
jpeg1.jpg
jpeg2.jpg
jpeg3.jpg
etc.
etc.
This converts the text doc to applescript list. If I uncomment my “Display dialog” at the end I can see that each file is cycling thru and filling the variable “thename” just fine. It works great if my .txt file has a small list or if my SOURCE_IMAGE folder contains a few images. However, when I target a .txt doc with a large amount of files or if my SOURCE_IMAGE folder has alot of files (more than 25) the script gives me this error:
Finder got an error: Can’t set alias “Macintosh HD:Users:de:Desktop:DESTINATION” to file named "
I think Jacques is right, DE. Your script repeats through the number of filtered files, but acts on the list of read names. Any names in the list that don’t belong to files that have passed the filter will cause an error.
But in fact you don’t need to use any repeats at all. Just change the filter:
with timeout of 600 seconds
--GET TEXT DOC INTO LIST FORM FOR COMPARISON TO FOLDER FILES
set aFile to (choose file with prompt "Select a file to read:" without invisibles)
set txt to (read aFile)
set para to paragraphs of txt
---------------------------------------------------------------
-- SET FOLDERS
set myfolder to choose folder with prompt "IMAGE FILES?"
set dstfolder to choose folder with prompt "DESTINATION FOLDER?"
---------------------------------------------------------------
--START PROCESS
tell application "Finder"
duplicate (every file of folder myfolder whose name is in para) to dstfolder
end tell
end timeout
Thanks for the suggestions. However, none of these seemed to help. Does anyopne know why my script works fine with a fewer amount of files as the filter or as the source? It seems to be a limit of somehere in the vicinoity of 25 files.
thanks!
Not sure I understand, DE. Are you still getting the same error as before - or a different one?
I ran your original script and the expected error resulted (for the reasons already outlined by Jacques and Nigel). After modifying it along the lines of Jacques’ suggestion, it worked - even when the text file contained names of files that didn’t exist in the folder. Not surprisingly, Nigel’s script performed even better, since it neatly avoids a couple of repeat loops, duplicates all the files in one hit - and even works when the text file contains duplicate names.
For the record, the source folder in my tests contained 200 files (of various types) and the text file contained 100 file names. All the files whose names were listed in the text file were duplicated successfully to the target folder.
In view of this, perhaps you could repost the latest version of the script that you’re trying - along with the text copied from your text file. It might be a good idea to wrap the script and copied text in ‘applescript’ and ‘code’ tags, like this:
```
your script here
```
(For the text, use ‘code’, instead of ‘applescript’.)
I’m sure that, with a bit more information, we can help you fix the problem.