https://github.com/cxa/cxadirectorycontentswatcher
Watch for a directory whenever a file is added or removed
https://github.com/cxa/cxadirectorycontentswatcher
Last synced: 11 months ago
JSON representation
Watch for a directory whenever a file is added or removed
- Host: GitHub
- URL: https://github.com/cxa/cxadirectorycontentswatcher
- Owner: cxa
- License: other
- Created: 2013-01-25T17:30:39.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2017-12-12T15:09:35.000Z (over 8 years ago)
- Last Synced: 2025-05-04T19:40:01.890Z (about 1 year ago)
- Language: Objective-C
- Homepage:
- Size: 15.6 KB
- Stars: 30
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CXADirectoryContentsWatcher
To handle files added or removed from iTunes File Sharing while app running motivates me to create this project.
Watching for the changes of a directory contents is easy with GCD `dispatch_source_t`, but to determine whether a file finished copying or not is very hard. With `DISPATCH_VNODE_ATTRIB` mask, the source will send an event when file will finish, if lucky we can receive another event after the copying is completely finished, but not always especially there are multiple files copying. So I do it the hard way, poll to check file size changing, when current size is equal to last check, I assume the copying job is done.
Any suggestion is welcome, seeking for the elegant solutions.
## Header at a glance
@protocol CXADirectoryContentsWatcherDelegate
- (void)directoryWatcher:(CXADirectoryContentsWatcher *)dirWatcher didFinishCopyItemAtURL:(NSURL *)fileURL isReplacement:(BOOL)isReplacement;
- (void)directoryWatcher:(CXADirectoryContentsWatcher *)dirWatcher didRemoveItemAtURL:(NSURL *)fileURL;
@end
@interface CXADirectoryContentsWatcher : NSObject
@property (nonatomic, weak) id delegate;
@property (nonatomic, strong, readonly) NSURL *directoryURL;
- (instancetype)initWithDirectoryURL:(NSURL *)dirURL delegate:(id )delegate;
- (BOOL)start;
- (void)stop;
@end
## Creator
* Twitter: [@_cxa](https://twitter.com/_cxa)
* Apps available on the App Store:
* PayPal: xianan.chen+paypal 📧 gmail.com, buy me a cup of coffee if you find it's useful for you.
## License
CXADirectoryContentsWatcher is released under the MIT license. In short, it's royalty-free but you must you keep the copyright notice in your code or software distribution.
For non attributed commercial lisence, please contact.