开发者

Comparing folder current state with saved prior state (C#)

开发者 https://www.devze.com 2022-12-21 02:22 出处:网络
I want to make a winform application that tells you wheneve开发者_开发技巧r you open it all the changes that have been made since last opening, and maybe record a log of it, such as:

I want to make a winform application that tells you wheneve开发者_开发技巧r you open it all the changes that have been made since last opening, and maybe record a log of it, such as:

  • File/folder creations
  • File/folder renamings
  • File/folder exclusions

I've figured i have to do four tasks:

  • Save the folder state (tree) in a reloadable format
  • Load this information back
  • Compare this information with current state gathered as needed
  • List changes, log and display them

I've come up with some ideas, what have you got to help me ?

(I'm vs 08 and .NET 3.5)

---[EDIT]---

Renaming should be impossible, it could just be an exclusion and a creation, since folders don't have unique ID's in Windows.

---[EDIT]---

The real purpose of it is learning, and if it works, i may as well use it and handle over the source code or something, I'm sorry for not mentioning this before, I'm not interested in ready solutions.

I want to watch a network shared folder, in which I already have an application currently in use (that i've made) that has a FileSystemWathcer to pop up a message balloon in the tray everytime something happens in any file or any folder/subfolder.

What i want is being able to compare the prior and current state in a separate application (initially) and if successfull, implement it in the currently running application. But that is quite irrelevant for the question.


My suggestion is to serialized the state into an XML file. Utilize XML Diff to create the diffgram and extract the information out from the diffgram produced for display. If you have the correct nested structure, diffgram will do the element matches and it will save you plenty of time from writing your own comparison of folder-folder and recursive sub folder comparison as well. All you need is to work out how to then digest the diffgram produced which is usually quite straight forward. Each element is usually marked with attribute to say that it is changed, added or deleted.


That's a good way to go.

Another idea is to use the NTFS change journal, as described in MSJ September 99 and MSJ October 99. The first run of the app has to enable the journal for the needed volume and it's done. The subsequent runs read the journal and extract the change info for the directory of interest.

Note that this is harder than it sounds as the API is quite low-level. And there is the - very small - risk that someone turns off the journal between runs.


Such an application already exists. It's called Subversion and there also exists a very good client for Windows called TortoiseSVN.

If you need to know what features your program needs or don't know how the UI should be designed, take a look into their documentations (subversion doc, tortoise doc) or even the source code.

Update

So if you just want to do this on your own for training purposes you should also take a look into the docs or the source code to get an idea on how they accomplished this task (eg. creating a hidden subfolder where the old state is saved) to get an idea how you can solve this problem for yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消