curiouswebster
asked on
What's wrong with this Objective-C?
Hi, I am trying to iterate through all the files in /Documents/Test/. I know there is one file there, but the following loop is not being entered by program execution:
for (NSURL *url in enumerator) {
void ProcessFolder(void)
{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *directoryURL = [[NSURL alloc]initFileURLWithPath: @"/Documen ts/Test" isDirectory:YES];
NSArray *keys = [NSArray arrayWithObject:NSURLIsDir ectoryKey] ;
NSDirectoryEnumerator *enumerator = [fileManager
enumeratorAtURL:directoryU RL
includingPropertiesForKeys :keys
options:0
errorHandler:^(NSURL *url, NSError *error) {
// Handle the error.
// Return YES if the enumeration should continue after the error.
return YES;
}];
for (NSURL *url in enumerator) {
NSError *error;
NSNumber *isDirectory = nil;
if (! [url getResourceValue:&isDirect ory forKey:NSURLIsDirectoryKey error:&error]) {
// handle error
}
else if (! [isDirectory boolValue]) {
// No error and it’s not a directory; do something with the file
}
}
}
for (NSURL *url in enumerator) {
void ProcessFolder(void)
{
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *directoryURL = [[NSURL alloc]initFileURLWithPath:
NSArray *keys = [NSArray arrayWithObject:NSURLIsDir
NSDirectoryEnumerator *enumerator = [fileManager
enumeratorAtURL:directoryU
includingPropertiesForKeys
options:0
errorHandler:^(NSURL *url, NSError *error) {
// Handle the error.
// Return YES if the enumeration should continue after the error.
return YES;
}];
for (NSURL *url in enumerator) {
NSError *error;
NSNumber *isDirectory = nil;
if (! [url getResourceValue:&isDirect
// handle error
}
else if (! [isDirectory boolValue]) {
// No error and it’s not a directory; do something with the file
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
You are welcome
ASKER