Simple list coercion. (Maybe not so simple?)

This is my first time posting to this forum. I need some help understanding a couple basics I don’t grasp yet.

It seems the most efficient way to process specific files within a folder is to first create a list of these files with the Finder and then pass the list along to other apps for processing. I am having trouble coercing lists of files into the type of list that other apps understand.

example:

set theFolder to alias "Macintosh HD:Users:jason:Desktop:Upload Test:"
tell application "Finder"
--this folder does contain folders but I do not want them in the list
	set theResult to every item of theFolder whose kind is not "Folder" as list
	get theResult
end tell

The result of this script gives me:
{document file “xxxxx.ai” of folder “XXXX” of folder “XXXXX” of startup disk of application “Finder”, document file “xxxxx.ai” of folder “XXXX” of folder “XXXXX” of startup disk of application “Finder”, document file “xxxxx.ai” of folder “XXXX” of folder “XXXXX” of startup disk of application “Finder”, document file “xxxxx.ai” of folder “XXXX” of folder “XXXXX” of startup disk of application “Finder”}

How do I coerce this type of list into a list that say—Cyberduck would understand?

Any suggestions are welcome. (Especially those that can tell me when my entire script writing premise is out-of-whack and then sets me straight.) And if I have missed a resource or forum that can easily solve me problem please direct me to it. Thanks!

The problem is not the list, but rather the items it contains. The Finder returns objects that aren’t useful outside of the Finder.

Try something like this:

set theResult to (every file of theFolder) as alias list

A very common stumbling block. I’ve always wondered why it was so.

Note that, due to a longstanding bug, coercing a list of Finder references to an alias list will result in a coercion error [number -1700] when the list contains only a single item. One way around this is to use a try statement:

tell application "Finder" to try
	set aliasList to theFolder's files as alias list
on error
	set aliasList to theFolder's files as alias as list
end try

Thank you very much. This works great! I could have sworn that I already tried “as alias list” but maybe I was forgetting the “( )”.

One last question:
Under the same circumstances as my first script… How do I get every nested file in this list? I would like to come up with a list that includes every file in a given folder, including files within folders, excluding files that are “folders”.

Once again, if there is an online resource that can answer this question please just point me to it. Thanks for sharing your time and expertise!

You can use the “entire contents” property:

tell application "Finder"
	set theResult to (every file of entire contents of theFolder) as alias list
end tell

Note that it can be slow for very large folders.

“entire contents” is the way to go!

Thanks for the assistance everyone. I will post my final script when I finish.
Thanks,
Simpleton