Entire contents of folder includes sub-sub-folders - want sub-folders

This code was designed to test existence of folders beginning with a specific job number.

The folders I want to test are all sub-folders of the specified JobsRangeFolder

It works but it can take several minutes to run. When I displayed “count of” it showed 13,000 items.

Since there can only be 100 subfolders in any JobsRangeFolder, it appears to be searching sub-sub folders and file names, as well.

How do I restrict the search to either just one level down in folders - or simply exclude file names?

local JobFolderFound

set JobFolderFound to false

set JobsRangeFolder to “JJSLO:Jobs Direct:10000-10099” as alias

tell application “Finder”
set JobsRangeFolderListAlias to ([b]entire contents of /b as alias list)
end tell

repeat with aParticularFolder from 1 to count of JobsRangeFolderListAlias
display dialog "The number of folders to check is " & (count of JobsRangeFolderListAlias)
set this_folder to item aParticularFolder of JobsRangeFolderListAlias
set RangeFolder_JobFolder_info to info for this_folder
copy displayed name of RangeFolder_JobFolder_info to JobFolderName
if JobFolderName begins with “10010” then
if not JobFolderFound then
set JobFolderFound to true
end if
end if
end repeat

if JobFolderFound then
display dialog “Job Number file for 10010 already exists”
else
display dialog “Job Number file for 10010 does not exist”
end if

I did find the syntax

set JobsRangeFolderListAlias to (every folder of entire contents of (JobsRangeFolder) as alias list

That limited the search to 1500 folders, which is an improvement.

Is there any syntax which would limit it to the one level down?

After chasing around a command reference, I was able to figure out how to do it with

name of folders of (…folder…)

which appears to only check the one level below and only involves “name” objects instead of entire folders.

It works!

If you have a more elegant way, I’d still like to hear it . (No shell commands, please. I’m not read to be “bashed”.


local JobFolderFound

set JobFolderFound to false

set JobsRangeFolder to “JJSLO:Jobs Direct:10000-10099” as alias

tell application “Finder”
set JobsRangeFolderList to ([b]name of folders of /b as list)
end tell
–display dialog "The number of folders to check is " & (count of JobsRangeFolderList)
repeat with aParticularFolder from 1 to count of JobsRangeFolderList

set this_folder to item aParticularFolder of JobsRangeFolderList

if this_folder begins with "10010" then
	if not JobFolderFound then
		set JobFolderFound to true
	end if
end if

end repeat

if JobFolderFound then
display dialog “Job Number file for 10010 already exists”
else
display dialog “Job Number file for 10010 does not exist”
end if

Hi. You seem to have proactively solved your own problem, and the code seems perfectly fine to me. If you want a shorter alternative, this will beep at you if the folder doesn’t exist.

tell application "Finder" to if not ((folder (alias "JJSLO:Jobs Direct:10000-10099:")'s folders) whose its name begins with "10010") ≠ {} then beep 2