And by the way, I just added some minimal code that if it encounters a package folder, add it to the file count without diving down into that package folder. Code works in the AppleScript editor, but identical code does not work in a Run AppleScript action because clicking the hammer icon (compile) of the AppleScript there forces some of the camelcase method name to lower case and the code fails when run for that reason.
This works in the Script Editor:
repeat with afileRef in dirEnumerator's allObjects()
set {result, isFile} to (afileRef's getResourceValue:(reference) forKey:NSURLIsRegularFileKey |error|:0)
if (isFile's boolValue()) = true then
(fileArray's addObject:(afileRef's valueForKey:"path"))
else if (nsws's isFilePackageAtPath:(afileRef's valueForKey:"path")) = true then
(fileArray's addObject:(afileRef's valueForKey:"path"))
end if
end repeat
and produces this result for one regular file and two package folder items at depth:
and the Automator Run AppleScript action does this to it:
repeat with afileRef in dirEnumerator's allObjects()
set {result, isFile} to (afileRef's getResourceValue:(reference) forKey:NSURLIsRegularFileKey |error|:0)
if (isFile's boolValue()) = true then
(fileArray's addObject:(afileRef's valueForKey:"path"))
else if (nsws's isFilepackageAtPath:(afileRef's valueForKey:"path")) = true then
(fileArray's addObject:(afileRef's valueForKey:"path"))
end if
end repeat
where the required uppercase 'P' in isFilePackageAtPath is changed to a lower case 'p' and the workflow fails because the method name is now wrong. I will be filing a bug report with Apple.