Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if the content of a folder was changed

I need a procedure that checks if new folders/files were added to a given selected folder. I need this procedure to run upon application start up so the processing time at this stage is important.

I guess I can make a log of current state, log of the previous state, sort and compare them.

  1. First I need to know if there is another way.

  2. Second if there is no other way what is the best way to find difference between two lists of files paths: both structure and algorithms.

Old state:

c:\firstfolder\a.doc
c:\firstfolder\b.doc
c:\firstfolder\secondFolder\a.doc
c:\firstfolder\secondFolder\b.doc

New state:

c:\firstfolder\a.doc
c:\firstfolder\b.doc 
c:\firstfolder\secondFolder\a.doc 
c:\firstfolder\secondFolder\b.doc 
c:\firstfolder\secondFolder\c.doc

I'm looking for c:\firstfolder\secondFolder\c.doc.

like image 263
Asaf Avatar asked Sep 04 '10 19:09

Asaf


1 Answers

You can use the FileSystemWatcher class, I think it's doing exactly what you are after.

like image 81
CyberDude Avatar answered Oct 13 '22 20:10

CyberDude