PDA

View Full Version : NSFileManager: Notification of moved files




MacDonaldsd
Feb 5, 2008, 07:43 AM
Hi all,

Im having a problem whereby I need to keep track of a few files on the system that my application keeps a URL reference to. The problem I am having is that I can't get any notification when these files are moved.

I tried the code below but it isn't working, the delegate methods never get called.

- (void)awakeFromNib
{

NSFm=[NSFileManager defaultManager];

[NSFm setDelegate:self];

NSLog(@"Delegate %@", [NSFm delegate]);


}


- (void)fileManager:(NSFileManager *)manager willProcessPath:(NSString *)path{
NSLog(@"File manager%@",manager);

}

- (BOOL)fileManager:(NSFileManager *)fileManagershouldMoveItemAtPath:(NSString *)srcPathtoPath:(NSString *)dstPath {

NSLog(@"File manager");
return YES;
}



kainjow
Feb 5, 2008, 12:24 PM
If you want to track files when they are moved, you can use aliases (from Carbon). One Cocoa wrapper is NDAlias (http://homepage.mac.com/nathan_day/pages/source.xml).

Catfish_Man
Feb 5, 2008, 12:54 PM
Yeah, NDAlias or similar is the way to go. As for why your code didn't work, you're fundamentally misunderstanding what NSFileManager does. It's isolated to just your application; so those delegate methods will only be called when you ask your NSFileManager instance to do something.

Also you mis-capitalized one of them.

MacDonaldsd
Feb 5, 2008, 03:35 PM
Ok thanks,

I thought that was the problem.

Its more of a case that if they are moved I want to delete there related in my application.