Pruned visit of a folder hierarchy

Hi,
I need the help of some AS guru again :slight_smile:

I want to process the content of a Finder folder by selecting the (top-level) subfolders that contain a certain internet location file. That is, I am looking for the equivalent of the following code:


set aFolder to path to documents folder -- For instance
tell application "Finder"
	set theResult to the folder of (every internet location file of (entire contents of aFolder) whose name begins with "MyLink")
end tell

but restricted to the first level of the subfolder hierarchy. I have tried with


set theResult to the location of (every internet location file of (every folder of aFolder) whose name begins with "MyLink")

but it results in “Unknown object type”. Why? Is there a way to fix it?

Curiously enough (at least for me), the following variations are all correct:


tell app "Finder"
set theResult to the location of (every internet location file of (some folder of aFolder) whose name begins with "MyLink") -- Ok
set theResult to the location of (every internet location file of aFolder whose name begins with "MyLink") -- Ok
set theResult to the location of (every internet location file of (every folder of aFolder)) -- Ok
end

but, of course, they do not achieve what I want.

Hi, druido.

The way filters are implemented in the Finder, you have to check the subfolders individually. But it’s not particularly slow:

set theResult to {}

set aFolder to path to documents folder -- For instance
tell application "Finder"
	set subFolders to folders of aFolder
	repeat with thisFolder in subFolders
		if (first internet location file of thisFolder whose name begins with "MyLink") exists then
			-- 'contents' here is the contents of the reference 'thisFolder', not the contents of the folder itself.
			set end of theResult to thisFolder's contents
		end if
	end repeat
end tell
theResult

Thanks for your reply! I hoped to be able to do it by sending a single message, but that is also fine.