0

I just got help to get file name of a chosen folder.

 tell application "Finder"
 name of files of folder (choose folder) -- names of files
 end tell

However, I can't get this working for a give path, like this one

 set myfile to name of files of folder "~/Downloads/test/"

I played around a lot with POSIX path and others, but I can't get this working. Could you please help me again, thanks.

1 Answer 1

3

This should do the trick:

tell application "System Events"

    set downloadsFolder to path to downloads folder as text
    -- display dialog downloadsFolder

end tell

tell application "Finder"

    set myFileNames to name of files of folder (downloadsFolder & "test:")
    log myFileNames

end tell

ADDITION:

set thisLocation to "/Volumes/Data/"

tell application "Finder"

    set myFileNames to name of files of folder (thisLocation as POSIX file)
    log myFileNames

end tell
Sign up to request clarification or add additional context in comments.

4 Comments

I can't get this working for external volumes, e.g., set downloadsFolder to path to "volumes:Data:" as text
BTW AS Editor has built-in code snippets, CTRL-CLICK into a script to see them.
I don't get the use of log in the script, we can see the result then why do we need log? thanks
You can just delete that line with the log. I usually insert them for educational purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.