Make a list of files into a folder placed on the desktop?

I want a list of file names contained into a folder placed on the desktop. What’s wrong with this:

    tell application "Finder" to set theFolder to ((path to desktop as text) & "REF FOLDER")
    tell application "Finder" to set my gList to (the name of every file in theFolder) as list

because I get :

   Can't get every file of "Macintosh HD:Users:<myName>:Desktop:REF FOLDER

and I’m just wondering why?

Ragards

Hi,

a literal string is no folder, use the specifier folder


tell application "Finder"
	set theFolder to ((path to desktop as text) & "REF FOLDER")
	set my gList to the name of every file in folder theFolder
end tell

or easier


tell application "Finder"
	set my gList to the name of every file in folder "REF FOLDER" of desktop
end tell

the as list coercion is not needed, the result of [property] of [elements] is always a list

Hello Stefan!

Sounds well, but gives error :

Can’t make «class ocid» id «data kptr60814F01» into type list, record or text. (error -1700)

I guess that gList is a AppleScriptObjC property, so maybe the as list coercion is indeed necessary
or try this


tell application "Finder"
	set nameList to the name of every file in folder "REF FOLDER" of desktop
end tell
set gList to nameList


Correct guess : property gList : {} – this is sufficient to declare it as a list ?

    tell application "Finder" to set tempList to the name of every file in folder "REF FOLDER" of desktop

    log tempList -- gives correct list, so the app finds the folder and read correctly into it, but --

    set my gList to tempList   -- or --
    set my gList to tempList as list  -- with or without "my" --

give the same:

    Can't make «class ocid» id «data kptrB0A54F01» into type list, record or text. (error -1700)

What’s going wrong? It only seems to be correct, but we are missing something… :confused:

Ok, I surrender. That’s what I try to do – without success. I need more help!

My application has to read some file contents when it is launched. These files are included into a folder named “REF FOLDER”.

Given the “property gRefPath : missing value” to store the path, and “property gFiles : {}” to store the files, it should do this:

a) Retrieve the path to a folder named “REF FOLDER” and store it into gRefPath (for the moment it is on the desktop, but ideally it should be into the “Resource” folder in the “Content” folder of the application bundle. I read pages and don’t understand how to do this;
b) Open the “REF FOLDER” and store its files into the gFiles list (= set my gFiles to the name of every file in folder gRefPath);
c) Open, and read contents, of each of these files using :
set fp to open for access gRefPath & item of gFiles as string

I know the app is capable to work if I hard-code the gRefPath, or if I get it using “Choose folder”. If I try to retrieve this path by “path to desktop” (don’t even think to the app bundle…) I hit the wall. Every attempt to change the code gives more and more errors. I prefer to stop and ask for help!

Regards

Found ! :smiley:

        set gRefPath to (current application's NSBundle's mainBundle's resourcePath) as text & "/REF FOLDER"
        set gRefPath to (gRefPath as POSIX file) as string
        tell application "Finder" to set my gList to the name of every file in folder gRefPath as list

and… a way to find a folder into my application’s bundle, on the same lines!

Thanks for being around, folks! You help me to find solutions, even if you don’t say anything!

Bernard