I have file tree in my Documents folder. What is the easiest way to watch all changes in Documents folder and in all its subfolders? I've already read about kqueue but it seems that it works only for folder itself(not for its subfolders).
Asked
Active
Viewed 748 times
0
-
What are you expecting to make changes that you don't know about? – Wain Oct 28 '13 at 10:18
-
possible duplicate of [Notification callback in iOS when iTunes sync/file transfer is complete](http://stackoverflow.com/questions/7850949/notification-callback-in-ios-when-itunes-sync-file-transfer-is-complete) – Wain Oct 28 '13 at 10:19
-
@Wain i've found out that one of bottlenecks of my app is [NSFileManager fileExistsAtPath:] calls, so I've decided to cache this call. But I need to know when some file was removed or added. – Siarhei Fedartsou Oct 28 '13 at 10:42
-
and I think that MHWDirectoryWatcher can watch only directory itself without subfolders – Siarhei Fedartsou Oct 28 '13 at 10:44
-
Just rescan whenever your app has been to the background and then regains foreground... – Wain Oct 28 '13 at 10:45
-
But some of subsystems of my app can for instance download some file from the Internet and add it to filesystem. I need to track such situation. – Siarhei Fedartsou Oct 28 '13 at 11:06
-
Post a notification / use a delegate. – Wain Oct 28 '13 at 11:06
-
possible duplicate of [Monitoring a directory in Cocoa/Cocoa Touch](http://stackoverflow.com/questions/7720246/monitoring-a-directory-in-cocoa-cocoa-touch) – eonil Nov 12 '14 at 02:43
1 Answers
0
The cost of scanning the file system is relatively high if you can't do it using a function built into the OS.
For iOS, your app file system can't really change while the app is running. iTunes can sync some file which may be an issue for you but generally, while the app is open, it is only the app that is making changes. So, the app should deal with this situation by posting notifications about the change events so that other classes inside the app can observe them and deal with the situation accordingly.
Your notifications can also include details of what changed in the userInfo
dictionary.

Wain
- 118,658
- 15
- 128
- 151
-
-
'you' being some code in your app - so it can post a notification just after doing that – Wain Oct 28 '13 at 11:20