I don’t understand the proper parameter syntax of this method. My target is to obtain a list of regular files from the Downloads folder (URL “pathToDownload” is OK), excluding the folders.
I already tried the predicate (without success, for me “predicateWithString” is too obscure) and I was wondering if enumeratorAtURL could filter this itself.
The enumeratorAtPath still returns “.DS_Store” for an empty folder, which is correct.
I’m not so sure, after reading the docs, that enumeratorAtURL: includingPropertiesForKeys is what I’m after. This method does not seem to filter the array.
the result of enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: is NOT an array.
Look into the documentation (NSFileManager Class Reference). There is an example how to handle the method
But there is a general misunderstanding. I guess fiz assumes that the enumerator method filters the items in the directory depending on the includingProperties array like NSPredicate does.
@fiz: All enumeratorAt. and contentsOf. methods of NSFileManager do not provide a function similar to NSPredicate except some of them can skip subdirectory descendants, package descendants and hidden files
Thank you for the discussion. Finally I use these methods (two fast enumerators and a multiple-condition IF:
Question 1:
In Pascal, we had a short-circuit evaluation. Note there are three conditions in the example above. If one is FALSE, then the entire expression is FALSE.
if (condition1 and condition2 and condition3) then. was fully evaluated.
if (condition1 & condition2 & condition3) then. was evaluated condition by condition and set to FALSE at first FALSE condition.
In Objective-C, && is always short-circuit, correct?
Question 2:
There is no way to get the size of a folder, but was is the ObjC equivalent of the ASOC:
set theSize to size of (info for theFolder as alias) -- which gives correct results ?
to use the routine on CocoaBuilder mentioned by Shane put the code as a method in the same class as the caller.
For example to retrieve the size of the Downloads folder, write
NSURL *downloadsFolderURL = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Downloads"]];
FSRef fsRef;
unsigned long long folderSize = 0;
if (CFURLGetFSRef((CFURLRef)downloadsFolderURL, &fsRef)) {
folderSize = [self fastFolderSizeAtFSRef:&fsRef];
NSLog(@"%lld", folderSize);
}