NSFileManager and -fileManager:shouldProceedAfterError:
NSFileManager and -fileManager:shouldProceedAfterError:
- Subject: NSFileManager and -fileManager:shouldProceedAfterError:
- From: David Martin <email@hidden>
- Date: Wed, 25 Dec 2002 19:51:03 +0100
Hi,
I've been reading the documentation for NSFileManager again and again,
but there's obviously something wrong with my understanding of it.
More specifically, I'm working with -[NSFileManager
movePath:toPath:handler:], and I'm trying to implement a "Stop or
Continue?" dialog box after an error occurs. I've got a -[NSFileManager
fileManager:shouldProceedAfterError:] method that handles that dialog
box, and that returns YES or NO, according to the button pushed.
Now, what I understand from the line in -[NSFileManager
movePath:toPath:handler:]:
"If the operation is not successful, but the handler method
fileManager:shouldProceedAfterError: returns YES,
movePath:toPath:handler: also returns YES; otherwise it returns NO."
is that it should return YES when -[NSFileManager
fileManager:shouldProceedAfterError:] returns YES.
However, with the following code, I always get "success: false" at the
end of the -trimFiles method, even if I can see the debugger step on
the "return YES;" line in -fileManager:shouldProceedAfterError:.
Does anyone understand what's going on?
Thanks,
David
- (void)trimFiles {
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtPath:[defaults objectForKey:METSourceFolder]];
NSString *file, *newFile;
BOOL success = YES;
while ((file = [enumerator nextObject]) && success) {
NSString *oldPath, *newPath;
if ([defaults integerForKey:METTrimPosition] == 0) {
newFile = [file substringFromIndex:[defaults
integerForKey:METTrimLength]];
} else if ([defaults integerForKey:METTrimPosition] == 1) {
newFile = [file substringToIndex:([file length] - [defaults
integerForKey:METTrimLength])];
}
oldPath = [[defaults objectForKey:METSourceFolder]
stringByAppendingPathComponent:file];
newPath = [[defaults objectForKey:METSourceFolder]
stringByAppendingPathComponent:newFile];
success = [[NSFileManager defaultManager] movePath:oldPath
toPath:newPath handler:self];
NSLog(@"success: %@", [NSNumber numberWithBool:success]);
}
[[NSWorkspace sharedWorkspace] noteFileSystemChanged:[defaults
objectForKey:METSourceFolder]];
}
- (BOOL)fileManager:(NSFileManager *)manager
shouldProceedAfterError:(NSDictionary *)errorInfo {
int result = NSRunAlertPanel(NSLocalizedString(@"File Manager
Error", nil), NSLocalizedString(@"File Manager Error Message", nil),
NSLocalizedString(@"Continue", nil), NSLocalizedString(@"Stop", nil),
nil, [[errorInfo objectForKey:@"Path"] lastPathComponent], [errorInfo
objectForKey:@"Error"]);
if (result == NSAlertDefaultReturn) {
return YES;
} else {
return NO;
}
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.