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
Chiyoko_S
Chiyoko_S3y ago
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 once
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
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
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
Hm ok
Chiyoko_S
Chiyoko_S3y ago
what are you trying to do now, exactly? by listening to the changes I mean
Luizdodibre
LuizdodibreOP3y ago
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
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
hm i can try
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
I think complex would be little '-' Yes.
Chiyoko_S
Chiyoko_S3y ago
So those are the filters that FileSystemWatcher supports
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
I thought of recording the name and time Ok
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
I'm doing this because I'm trying to "create" an ""antivirus""
Chiyoko_S
Chiyoko_S3y ago
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
Luizdodibre
LuizdodibreOP3y ago
that. i am creating it just to learn more about c#
Chiyoko_S
Chiyoko_S3y ago
ah, fine then have fun owo
Luizdodibre
LuizdodibreOP3y ago
blushowo
Want results from more Discord servers?
Add your server