I have a folder containing a hierarchy of subfolders and files.
At regular intervals, I need to check whether any file/folder has been modified/removed/added.
I am thinking of developing from scratch an algorithm that:
- Saves a representation of the whole arborescence in an embedded database (like SQLite) or file.
- Saves the checksum of each file into the same database.
- At the next call, compare this database with the actual filesystem.
- Update the database’s information with what is found to have been changed.
- Repeat from step 3.
Changes might occur while my program is not running, it can be closed/open at any time.
For instance the user might close the program on Monday, edit files on Tuesday, and re-open the program on Wednesday. I need to check what changed during that time, so I can’t use FileSystemWatcher.
Before I reinvent the wheel, is there already some library that does this?
Note:
- I don’t have access to any VCS binaries like
gitorsvn. - Language is C#, but I am ready to port any small Java library.
- This is for an open source software, so it needs to be an open source library.
- It is for a embedding into a desktop widget, so the lighter the better.
If you can’t use the FileSystemWatcher (which I hate anyways, it’s the flakiest class in the framework IMO) your only other option is to manually keep track of the files. You will need to store the filenames and a hash of the file contents to check if the files are added/removed or changed. I would store this using a Database either SQLExpress or SQLite which has a C# wrapper.
Your program would check the files on start/stop and then I would use a timer while it’s running to periodically check the files.
Edit: Clarification from the OP, I don’t know of any library that does this out of the box. However it would be trivial to implement on your own. A small DB with one table, and a timer control in a console application or windows service would do exactly what you need.