[Solved] to get folders from directory between the dates entered in two textboxes


If you want to filter the files you are gonna iterate through, you can use System.IO‘s FileInfo class instead if File. Then you filter the files by their CreationDate property:

DateTime yourstartDate = new DateTime();
DateTime yourEndDate = new DateTime();
DirectoryInfo di = new DirectoryInfo("any_directory");
List<FileInfo> fis = di.GetFiles().Where(x => x.CreationTime >= yourstartDate && x.CreationTime <= yourEndDate).ToList()
// your can iterate this list now with for or foreach

Example

I will create .txt files and store the timestamp before and after creating the second file.

File.Create("C:/temp/file1.txt");
DateTime start = DateTime.Now;
File.Create("C:/temp/file2.txt");
DateTime end = DateTime.Now;
foreach (FileInfo fi in new DirectoryInfo("C:/temp").GetFiles().Where(x => x.CreationTime >= start && x.CreationTime <= end))
{
    // will only get file2.txt
}

0

solved to get folders from directory between the dates entered in two textboxes