0

I am trying to watch the downloads directory of a mac OS X using an Xcode created application. Below is the code used for my attempt at logging a file being moved. However when I goto my documents and move a file, the delegate method is not even called. Is there a proper way to do this that I am missing?

- (void)viewDidLoad {
    [super viewDidLoad];
    NSFileManager *manager = [[NSFileManager alloc] init];    // Do any additional setup after loading the view.
    [manager setDelegate:self];


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder

    [manager changeCurrentDirectoryPath:documentsDirectory];
}

- (BOOL)fileManager:(NSFileManager *)fileManager shouldMoveItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath{
    NSLog(@"Attempt to move");
    return YES;
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
CoderJ
  • 21
  • 1
  • 3
  • 1
    iOS or OSX? It's unclear. http://stackoverflow.com/questions/1386743/observe-a-file-or-folder-in-objective-c ? – Larme Nov 04 '15 at 17:37

1 Answers1

0

shouldMoveItemAtPath does not monitor file changes.

You need to use FSEvents to get events signalling file system changes.

john elemans
  • 2,578
  • 2
  • 15
  • 26
  • That is what I feared, I have not seen any good tutorials/examples of the FSEvents. I will look deeper, thanks. – CoderJ Nov 05 '15 at 00:58