List of files --> Duplicate them how?

I suspect this may have been answered previously but I’ve searched to no avail. Hence the post.
Problem: Duplicate a large number of specific files.

Strategy: Read text file listing specified files. (one file per line)
Read one line, duplicate file specified on that line.
Go to next line

Attempted code:


-- Duplicate files from FileList.txt
-- FileList.txt = Listing of files, one file per line.

set Filenames to paragraphs of (read alias "Disk:Folder:FileList.txt")
repeat with ThisName in Filenames
	tell application "Finder"
		duplicate ThisName to "Disk:Folder:NewFolder"
	end tell
end repeat

Code does not work. What am I missing?
Is there alternative coding strategy?

Hi.

If the list only contains the names of the files, your script won’t work - you need the alias. As a quick test, I saved a text file with an alias - not just the name - on one line, and your script worked.

If all the files are in the same folder, and the file name includes the extension, you could easily use a variable to complete the alias:


-- Duplicate files from FileList.txt
-- FileList.txt = Listing of files, one file per line.

set Filenames to paragraphs of (read alias "Disk:Users:UserName:Folder:FileList.txt")
set thePath to "Disk:Users:UserName:Folder:"
repeat with ThisName in Filenames
	tell application "Finder"
	set ThisName to thePath & ThisName
		duplicate ThisName to "Disk:Users:UserName:Folder:NewFolder"
	end tell
end repeat

Read the event log of this if I’m being unclear.

tell application "Finder"
	set theFile to (choose file without invisibles)
	duplicate theFile to "Disk:Users:UserName:Folder"--fix this, obviously
end tell

Of course, if the files are all in one folder, you wouldn’t need to read the FileList.txt. If the files are not stored together, you’ll need a way to to get each alias. That might be difficult.

Hope that helps.

j

Mucho Appreciado!!

Your explanation helped clarify a few things in my list of files.

There was also a problem with the text file with the file names.
I didn’t use TextEdit to create the file so Applescript choked on the end of line character used by the other program.
Once it was entered into TextEdit, it worked beautifully!

Thanks for your help!

taubasl

Looks like the main problem was something I overlooked. Well, I’m glad to have been of what little assistance I actually was.