Files on desktop
I want to check files that have been added or edited (I thought of using fileSystemWatcher but every time I edited a file it was executed 3 times (but I don't know if this is the best way)) continuing.. I want to check the files from desktop to know if a file has been added or edited and my main point is to get the path of the edited file (if anyone can give me an idea on how to do this I would be very grateful (remembering that I don't know if fileSystemWatcher is the best way to check that)
22 Replies
What do you mean "executed 3 times"?
ah, it does seem to raise
Changed
event twice for me when edited, interesting
I actually wonder if it is how edits are handled by programs
because, when I edit a textfile in VSCode, the event is raised twice
but when I edit it in notepad it's raised only onceUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah seems likely
besides, I don't really see any problem with just using FileSystemWatcher
the most efficient way to watch for changes would be to just use whatever the OS provides
which FileSystemWatcher likely is already using
Ok
when i edited a text file in notepad it executed event 3 times
when i get back from my trip i will send the code for you to see
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
one way you could investigate is to instantiate multiple instances, each listening for a specific change via specifying different filters - then by looking at which listeners are triggered you could find out what are edited
not that it matters, anyway - as pntx said it's expected
Hm ok
what are you trying to do now, exactly?
by listening to the changes I mean
I'm trying to know if any edited file has a specific hash(md5) if it does I show a message in the console
I'll put it another way: if the file that was added or edited has the md5 that I defined it shows a message in the console
I was thinking of something like a delay queue, basically a queue where items are inserted and inserted items are dequeued once after a specific time has passed; except in this case, when an item already in the queue is queued again, the timer for that item starts again instead of queueing duplicates
hm i can try
so if three updates show up, you don't have to calculate the hash 3 times, because it'd happen while the item is on the queue & you calculate the hash with just the latest content
but I imagine how complex that could be
so uh
instead
you're just calculating the hash right
I think complex would be little '-'
Yes.
So those are the filters that FileSystemWatcher supports
what causes the hash to change, is when any changes are actually made to the file
so perhaps you could just listen for LastWrite | Size?
and maybe that'll cause the events to fire a little less
I thought of recording the name and time
Ok
that's just random thoughts. Dunno if that'll work for you
hell, I don't even know why you're comparing the content using a specific hash
because any change, including the change you don't necessary care, will end up changing the hash value
and hash values don't mean anything on its own
I'm doing this because I'm trying to "create" an ""antivirus""
that seems like a very fragile way to implement an antivirus but
maybe this is just a fun toy project so you don't care
because "viruses" can exist in many different formats
they could come as powershell / cmd scripts
that. i am creating it just to learn more about c#
ah, fine then
have fun