Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Notify Enum CreateEvent info issue with Windows OS
The problem I'm facing is regarding the use of the CreateEvent Enum as I am building a daemon to log all file and folder activities on my device, The problem though is that when trying to grab the specific type of CreateEvent Taking place, it just returns any every single time, someone pointed out to me it may be a problem of the windows OS an that it doesn't bother to check which is which, so It keeps triggering the neither case in the message_simplyfier function. I was hoping someone more englightened on notify crate's relationship with windows OS could help me
use notify::{event::CreateKind, Event, RecursiveMode, Result, Watcher};
use std::{path::Path, sync::mpsc};
use notify::EventKind;
// use notify::event::CreateKind;
fn main() -> Result<()> {
let (tx, rx) = mpsc::channel::<Result<Event>>();
// Use recommended_watcher() to automatically select the best implementation
// for your platform. The `EventHandler` passed to this constructor can be a
// closure, a `std::sync::mpsc::Sender`, a `crossbeam_channel::Sender`, or
// another type the trait is implemented for.
let mut watcher = notify::recommended_watcher(tx)?;
// Add a path to be watched. All files and directories at that path and
// below will be monitored for changes.
watcher.watch(Path::new("C:\\Users\\demio\\Downloads"), RecursiveMode::Recursive)?;
// Block forever, printing out events as they come in
for res in rx {
match res {
// Ok(event) => println!("event: {:?}", event),
Ok(event) => message_simplyfier(Ok(event)),
Err(e) => println!("watch error: {:?}", e),
}
}
Ok(())
}
fn message_simplyfier(message: Result<Event>) -> (){
let longinfo= message.unwrap();
match longinfo.kind {
EventKind::Remove(_) => println!("File was removed"),
EventKind::Modify(_) => println!("File was modified"),
EventKind::Create(c_kind) => match c_kind {
CreateKind::Folder => println!("A folder was created"),
CreateKind::File => println!("A file was created"),
neither => println!("Neither folder nor file: {neither:?}"),
},
EventKind::Access(_) => println!("File was accessed"),
_ => println!("Something else happened")
}
}
1 post - 1 participant
🏷️ Rust_feed