Behind the syntax of files of folder

Hi all,
I don’t understand why if I interrogate the Finder to extract filenames from files located into a folder, it works. But if I copy this files into a list then I get try to retrieve the filename I get an error.
See code below:

set theFolder to choose folder with prompt "Choose a folder"
-- get information about contents
tell application "Finder"
	get files of theFolder
	(item 1 of theFolder)'s class --> document file
	get displayed name of item 1 of theFolder --> a single filename
	get displayed name of files of theFolder --> a list of filenames 
	set myList to (files of theFolder) -- this list is equivalent to "get files of theFolder" as structure and contents
	(item 1 of myList)'s class --> document file
	get displayed name of item 1 of myList --> OK:  a single filename
	get displayed name of items of myList -- ERROR, Why?
	get displayed name of every item of myList -- ERROR, Why?
	get displayed name of files of myList -- ERROR, Why?
end tell

Thanks

At a guess the displayed name is not the file name. The displayed name is the name of the of file without its extension, try just name, not display name.

Hope this helps
Dave

My understanding is that you are facing what is described in Applescript User Guide:

Filter
Specifies all objects in a container that match a condition, or test, specified by a Boolean expression.
The filter form specifies application objects only. It cannot be used to filter the AppleScript objects list (page 112), record (page 118), or text (page 123). A term that uses the filter form is also known as a whose clause.
Note: You can use the words where or that as synonyms for whose.
A filter reference form can often be replaced by a repeat statement, or vice versa. For example, the following
script closes every TextEdit window that isn’t named “Old Report.rtf”:

Always my understanding, when we ask directly to the Finder, we urge it to search in a structure which it owns.
When we encapsulate the structure in an AppleScript’s list we introduce an extraneous level of abstraction which fools the Finder.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 12:09:29

Wrong, the behavior is the same when the displayed name contains the extension as it does on my machine.
In fact, logically, it’s the same for every asked property.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 12:12:38

You are right. But this is not the point.
I know I can retrieve the display names from myList the using a loop. But why is not working when I want to get all display names at once? But it work if I retrieve it using:
get displayed name of files of theFolder

The structure and the content of:
“get files of theFolder”
is exactly as that of the myList, which is:
{document file “A.pdf” of folder “PDFs Join” of folder “Desktop” of folder “ldicroce” of folder “Users” of startup disk, document file “B.pdf” of folder “PDFs Join” of folder “Desktop” of folder “ldicroce” of folder “Users” of startup disk, document file “C.pdf” of folder “PDFs Join” of folder “Desktop” of folder “ldicroce” of folder “Users” of startup disk}

This might explain it. Thanks.

@ldicroce

Thank you, I corrected my typo :rolleyes:

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 2 mai 2020 12:24:17

Hi. The underlying problem is known as dereferencing, and it’s not Finder-specific. If you want to obtain multiple properties from an object en masse, do it while the reference is active.

tell application "Finder" to set {theFiles, theNames} to my (choose folder with prompt "Choose a folder")'s files's {it, displayed name}

Interesting line of code!
Although on my MacBook is a bit slow …
Thanks Marc Anthony.