All Projects → gurinderhans → SwiftFSWatcher

gurinderhans / SwiftFSWatcher

Licence: other
A simple easy to use / extend File System watcher using Swift

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to SwiftFSWatcher

watcher
The file system watcher that strives for perfection, with no native dependencies and optional rename detection support.
Stars: ✭ 37 (+5.71%)
Mutual labels:  filesystem, watcher
rorshach
A watchman for your directories. Rorshach allows you to listen to file system changes and run commands when these events occur.
Stars: ✭ 26 (-25.71%)
Mutual labels:  filesystem, watcher
Chokidar
Minimal and efficient cross-platform file watching library
Stars: ✭ 8,538 (+24294.29%)
Mutual labels:  filesystem, watcher
fswatch
File/Directory Watcher for Modern C++
Stars: ✭ 56 (+60%)
Mutual labels:  filesystem, watcher
Notify
🔭 Cross-platform filesystem notification library for Rust.
Stars: ✭ 1,123 (+3108.57%)
Mutual labels:  filesystem, watcher
chokidar-socket-emitter
a simple chokidar watcher which emits events to all connected socket.io clients
Stars: ✭ 28 (-20%)
Mutual labels:  filesystem, watcher
VBCorLib
The VBCorLib framework brings many of the powerful .NET classes to VB6.
Stars: ✭ 81 (+131.43%)
Mutual labels:  filesystem
whichpm
Locates installed Perl modules.
Stars: ✭ 20 (-42.86%)
Mutual labels:  filesystem
fat32
[New Version] This is FAT32 FileSystem Library, which is #![no_std] and does not use alloc.
Stars: ✭ 25 (-28.57%)
Mutual labels:  filesystem
flysystem-sync
Filesystem sync using Flysystem project.
Stars: ✭ 26 (-25.71%)
Mutual labels:  filesystem
AsyncIO
.NET library for handling asynchronous file system operations
Stars: ✭ 20 (-42.86%)
Mutual labels:  filesystem
tarfs
An implementation of the FileSystem interface for tar files.
Stars: ✭ 50 (+42.86%)
Mutual labels:  filesystem
chicon-rs
A file abstraction system for Rust
Stars: ✭ 55 (+57.14%)
Mutual labels:  filesystem
encfs4win
Windows port of EncFS
Stars: ✭ 356 (+917.14%)
Mutual labels:  filesystem
itree
Interactive tree command for file system navigation
Stars: ✭ 18 (-48.57%)
Mutual labels:  filesystem
exuberant
React filesystem renderer
Stars: ✭ 52 (+48.57%)
Mutual labels:  filesystem
node-clouddrive
Node SDK and CLI for Amazon's Cloud Drive
Stars: ✭ 74 (+111.43%)
Mutual labels:  filesystem
vk-music-fs
FUSE file system for VK audios
Stars: ✭ 34 (-2.86%)
Mutual labels:  filesystem
core
An advanced and highly optimized Java library to build frameworks: it's useful for scanning class paths, generating classes at runtime, facilitating the use of reflection, scanning the filesystem, executing stringified source code and much more...
Stars: ✭ 100 (+185.71%)
Mutual labels:  filesystem
meerkat
Watch your following activities on Instagram.
Stars: ✭ 31 (-11.43%)
Mutual labels:  watcher

SwiftFSWatcher

A simple easy to use / extend File System watcher using Swift

Please file any bugs you may encounter in the newer or even the current older version!

Example (Swift)

import Cocoa
import SwiftFSWatcher

class ViewController: NSViewController {

    // NOTE: - Any instance of `SwiftFSWatcher` must be class scoped, like below:

    /* This will not crash your app. */
    let fileWatcher = SwiftFSWatcher(["/var/www/html/", "/home/Downloads/"])
    let anotherWatcher = SwiftFSWatcher()

    override func viewDidLoad() {
        super.viewDidLoad()

        /* Using `localWatcher` will crash your app. */
        // let localWatcher = SwiftFSWatcher()

        fileWatcher.watch { changeEvents in
            for ev in changeEvents {
                print("eventPath: \(ev.eventPath), eventFlag: \(ev.eventFlag), eventId: \(ev.eventId)")

                // check if this event is of a file created
                if ev.eventFlag == (kFSEventStreamEventFlagItemIsFile + kFSEventStreamEventFlagItemCreated) {
                    print("created file at path: \(ev.eventPath)")
                }

            }
        }

        // setup and listen second watcher events on files only
        anotherWatcher.watchingPaths = ["/home/myFile.txt", "/root/bash_session.txt"]
        anotherWatcher.watch { changeEvents in
            for ev in changeEvents {
                print("eventPath: \(ev.eventPath), eventFlag: \(ev.eventFlag), eventId: \(ev.eventId)")

                if ev.eventFlag == (kFSEventStreamEventFlagItemIsFile + kFSEventStreamEventFlagItemInodeMetaMod + kFSEventStreamEventFlagItemModified) {
                    print("file modified at: \(ev.eventPath)")
                }
            }
        }
    }
}

Example (Objective-C)

#import "ViewController.h"
#import <SwiftFSWatcher/SwiftFSWatcher-Swift.h>

@implementation ViewController

SwiftFSWatcher * s;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    s = [[SwiftFSWatcher alloc] init];
    
    s.watchingPaths = [@[@"/path/to/some/folder/", @"/path/to/myFile.txt"] mutableCopy];
    
    [s watch:^(NSArray<FileEvent *> * aa) {
        NSLog(@"changed paths: %@", aa);
    }];
}
@end

Installation (two ways)

  • Include pod 'SwiftFSWatcher' in your Podfile

    • You'll need to add use_frameworks! since the framework is built in Swift.
  • Grab the SwiftFSWatcher.framework and add it to your project or build the .framework yoursleves by downloading this project.

  • Use it in your app

Questions?

Have a question? Feel free to email me.

You added a new feature?

Send it in right now! I can't wait to see what you've done!

Found a Bug?

Oh No! Send in a pull request with the patch (very much appreciated) or just contact me :D

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].