beginner trouble: can't assign contents of folder to variable / list

Hello,

I’m working on my first script, and still learning the basics. I’m running into a bit of trouble at the very beginning that I don’t quite understand, as I’ve copied some code directly from other people’s scripts that seem to work for them.


tell application "Finder"
	activate
	set target_folder to "/Users/me/Documents/targetfolder/"
	set files_list to every file of target_folder
end tell

I’m just getting an error saying:

‘Can’t get every file of “/Users/me/Documents/targetfolder/”’

I’m missing something very elementary, it seems
:wink:

Model: iMac 2.66 GHz
AppleScript: 2.2.1
Browser: Chrome
Operating System: Mac OS X (10.5)

ok, clearly i’m just not savvy on how to denote file paths correctly.
i am getting confused, because to create the script i’m just dragging & dropping the folder from a finder window into the script. i assumed this would render the filepath correctly.

if i use “choose folder” rather than an absolute filepath, the script works fine.


set theFolder to choose folder
tell application "Finder"
	set theFiles to every file of entire contents of theFolder
end tell

i’ll look for filepath info, but would anyone be willing to help me out with a link to good info on this as well?

thx!

Hi,

AppleScript works only with HFS paths (colon separated) and doesn’t accept POSIX paths (slash separated).
With a literal string it looks like “Mac HD:Users:me:Documents:targetfolder:”
but there is a “shortcut” for the documents folder of the curent user

set target_folder to ((path to documents folder as text) & "targetfolder:")

tell application "Finder"
	activate
	set files_list to every file of folder target_folder
end tell

Note: the specifier folder in front of the path string is necessary

thank you!
sometimes the simplest problems are the most frustrating ones.
:smiley:

You said it.

Model: MacBook Air 2.13GHz
Browser: Firefox 3.6.10
Operating System: Mac OS X (10.6)