Hi,

I'm having a problem with moving files using moveItemAtPath:toPath:error from NSFileManager. The operation moves a file as it should, but associated delegate method is not called (fileManager:shouldMoveItemAtPath:toPath). If I switch from moving to copying (that is when I use copyItemAtPath:toPath:error instead of moveItemAtPath:toPath:error) the equivalent delegate works fine. I made a sample source code to show what the problem is - I'm including it below. When I compile it and run in XCode 3.1.3 (on OSX 10.5.7) it just prints "OK" and not "Test move" so that the delegate is not called. And the file is moved as it should be...

Have you seen this before?

Regards

#import <Foundation/Foundation.h>

@interface Test : NSObject {
}
- (BOOL)fileManager:(NSFileManager *)fileManager shouldMoveItemAtPath: (NSString *)srcPath toPath:(NSString *)dstPath;
@end

@implementation Test
- (BOOL)fileManager:(NSFileManager *)fileManager shouldMoveItemAtPath: (NSString *)srcPath toPath:(NSString *)dstPath {
        NSLog(@"Test move");  
        return YES;
}
@end


int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSFileManager *fm = [NSFileManager defaultManager];     
if ([fm createFileAtPath:@"./test.txt" contents:@"test" attributes:nil]) {
        
                Test *t = [[Test alloc] init];
                [fm setDelegate:t];
        
                NSError *err;
if ([fm moveItemAtPath:@"./test.txt" toPath:@"./test1.txt" error:&err] == NO) {
                        NSLog(@"Error: %@", [err localizedDescription]);
                } else {
                        NSLog(@"OK");
                }
                [t release];
        } else {
                NSLog(@"Cannot create a test file");
        }
        
   [pool drain];
   return 0;
}
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to