NSFileManager: Notification of moved files

Discussion in 'Mac Programming' started by MacDonaldsd, Feb 5, 2008.

  1. macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #1
    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.

    Code:
    - (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;
    }
    
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If you want to track files when they are moved, you can use aliases (from Carbon). One Cocoa wrapper is NDAlias.
     
  3. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #3
    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.
     
  4. thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #4
    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.
     

Share This Page