I am trying to build a shallow search for files only. I modified a recursive search for files and that works fine. I can’t figure out why the contentsOfDirectoryAtURL search fails. Below are the 2 routines
on listFolder:folderPath
– shallow search, this returns files only, supply with POSIX path
set thePaths to {}
set theURL to current application’s NSURL’s fileURLWithPath:folderPath
set fileManager to current application’s NSFileManager’s defaultManager()
set propertyKeys to current application’s NSArray’s arrayWithObject:(current application’s NSURLIsDirectoryKey)
set theOptions to ((current application’s NSDirectoryEnumerationSkipsHiddenFiles) as integer)
–set theEnumerator to fileManager’s contentsOfDirectoryAtURL:theURL ¬
– includingPropertiesForKeys:propertyKeys options:theOptions errorHandler:(missing value)
set theEnumerator to fileManager’s contentsOfDirectoryAtURL:theURL ¬
includingPropertiesForKeys:propertyKeys options:theOptions |error|:(missing value)
repeat
set aURL to theEnumerator’s nextObject()
if aURL is missing value then exit repeat – missing value means there are no more
set {isValid, isDirectory} to (aURL’s getResourceValue:(reference) forKey:(current application’s NSURLIsDirectoryKey) |error|:(missing value))
if (isDirectory as boolean) is false then
set end of thePaths to (aURL's |path| as text)
end if
end repeat
return thePaths
end listFolder:
on returnFilePathsIn:folderPath
– recursive search, this returns files only, supply with POSIX path
set thePaths to {}
set theURL to current application’s NSURL’s fileURLWithPath:folderPath
set fileManager to current application’s NSFileManager’s defaultManager()
set propertyKeys to current application’s NSArray’s arrayWithObject:(current application’s NSURLIsDirectoryKey)
set theOptions to ((current application’s NSDirectoryEnumerationSkipsPackageDescendants) as integer) + ((current application’s NSDirectoryEnumerationSkipsHiddenFiles) as integer)
set theEnumerator to fileManager’s enumeratorAtURL:theURL ¬
includingPropertiesForKeys:propertyKeys options:theOptions errorHandler:(missing value)
repeat
set aURL to theEnumerator’s nextObject()
if aURL is missing value then exit repeat – missing value means there are no more
set {isValid, isDirectory} to (aURL’s getResourceValue:(reference) forKey:(current application’s NSURLIsDirectoryKey) |error|:(missing value))
if (isDirectory as boolean) is false then
set end of thePaths to (aURL's |path| as text)
end if
end repeat
return thePaths
end returnFilePathsIn:
In the first routine, I commented out the first attempt as it failed at that step. But if I change out the variable errorHandler for |error| it then fails at the first step of my repeat. I’ve looked for typos in BBEdit found none. Is there some other difference between the 2 “AtURL” commands?
I’m running on 10.10.2, my XCode libraries are 6.1.1