Previous | Index | Next |
URL and File related methods
resourceValuesForKeys:forFoldersIn:recursive:
As resourceValuesForKeys:forFoldersIn:recursive:skipHidden:skipInsidePackages:, skipping hidden folders and folders inside packages.
+ (NSArray *)resourceValuesForKeys:(NSArray *)resourceKeys forFoldersIn:(NSArray *)urlFolderOrPath recursive:(BOOL)recurseFlag
resourceKeys = array or list of resource keys
urlFileOrPath = alias, file, HFS path, POSIX path or NSURL
recurseFlag = whether to recurse through any folders
Array of dictionaries/records of resource key values for folders (excluding packages)
Version 1.3.0
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set urlFileOrPath to "~/Desktop"
set resourceKeys to {current application's NSURLAddedToDirectoryDateKey, current application's NSURLCreationDateKey}
set theResult to current application's SMSForder's resourceValuesForKeys:resourceKeys forFoldersIn:urlFileOrPath recursive:true
ASify from theResult
--> {{NSURLCreationDateKey:date "Tuesday, 9 June 2015 at 10:53:10 AM", _NSURLPathKey:"/Users/shane/Desktop/10.11 Changes", NSURLAddedToDirectoryDateKey:date "Friday, 25 September 2015 at 5:39:05 PM"}, [...]}
theResult as list -- 10.11 only
--> {{NSURLCreationDateKey:date "Tuesday, 9 June 2015 at 10:53:10 AM", _NSURLPathKey:"/Users/shane/Desktop/10.11 Changes", NSURLAddedToDirectoryDateKey:date "Friday, 25 September 2015 at 5:39:05 PM"}, [...]}
theResult as list -- 10.9 and 10.10
--> {{NSURLCreationDateKey:(NSDate) 2015-06-09 00:53:10 +0000, _NSURLPathKey:"/Users/shane/Desktop/10.11 Changes", NSURLAddedToDirectoryDateKey:(NSDate) 2015-09-25 07:39:05 +0000}, [...]}
set sortDesc to current application's NSSortDescriptor's sortDescriptorWithKey:(current application's NSURLCreationDateKey) ascending:true
set sortedValues to theResult's sortedArrayUsingDescriptors:{sortDesc}
set thePaths to sortedValues's valueForKey:(current application's NSURLPathKey)
ASify from thePaths
--> <recursive list of POSIX paths of folders sorted by creation date>
thePaths as list
--> <recursive list of POSIX paths of folders sorted by creation date>
thePaths as list -- 10.11 only
--> <recursive list of file references of folders on Desktop>
thePaths as list -- 10.9 and 10.10
--> <recursive list of NSURLs of folders on Desktop>