c# - Get all files in directory and subdirectory after date range -
this question has answer here:
- getting files creation date in .net 4 answers
is there way files in directory , subdirectories after date range?
i know directory.getfiles()
can iterate folders not give me access file object in can if statement on.
you use file.getcreationtime
, searchoption.alldirectories
, example:
var allfilesin2015 = directory.enumeratefiles("dir-path", "*.*", system.io.searchoption.alldirectories) .where(path => file.getcreationtime(path).year == 2015) .tolist();
you use fileinfo
s , it's properties creationtime
or lastaccesstime
:
directoryinfo dir = new directoryinfo("dir-path"); var allfileinfosin2015 = dir.enumeratefiles("*.*", system.io.searchoption.alldirectories) .where(fi => fi.creationtime.year == 2015) .tolist();
i use enumeratefiles
since more efficient in case. not need load files memory before can start processing them.
quote:
the enumeratefiles , getfiles methods differ follows: when use enumeratefiles, can start enumerating collection of names before whole collection returned; when use getfiles, must wait whole array of names returned before can access array. therefore, when working many files , directories, enumeratefiles can more efficient.
Comments
Post a Comment