file io - C# - Get LastWriteTime of A Folder's Descendants -


how can retrieve latest write time of any descendant of folder?

i need method return paths of files modified after specified datetime. figured save lot of expensive disk reading making sure directory lastwritetime within specified range before going through trouble of iterating through files , subdirectories.

this works in when file within top level of directory changes, last write time of folder updated well. however, last write time not bubble further file's immediate parent. in other words, if grandchild file changed, property updated, , it's father folder's, not grandfather.

is there high-level indicator can use accomplish this, or have resort recursing through every folder regardless of last change time?

here method stands:

private void addallfilesofallsubdirswithfiltertolist(string dirpath, ref list<fileinfo> fileslist, datetime mindate) {     // return files in directory level     foreach (string filepath in directory.getfiles(dirpath, "*.*", searchoption.topdirectoryonly))     {         fileinfo fileinfo = new fileinfo(filepath);         if (fileinfo.lastwritetimeutc > mindate)         {             fileslist.add(fileinfo);         }     }      // return recursive searches through sudirs     foreach (string subdirpath in directory.getdirectories(dirpath))     {         directoryinfo dirinfo = new directoryinfo(subdirpath);         if (dirinfo.lastwritetimeutc > mindate)         {             getallfilesofallsubdirswithfilter(subdirpath, ref fileslist);         }     } } 

sorry think have go through subdirectories.

just change searchoption code above recurse through subdirectories...

private void addallfilesofallsubdirswithfiltertolist(string dirpath, ref list<fileinfo> fileslist, datetime mindate) {     // i'm assuming want clear here... return      //   instead of passing ref     fileslist.clear();      // return files in directory tree     foreach (string filepath in directory.getfiles(dirpath, "*.*", searchoption.alldirectories))     {         fileinfo fileinfo = new fileinfo(filepath);         if (fileinfo.lastwritetimeutc > mindate)         {             fileslist.add(fileinfo);         }     } } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -