Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does EnumerateFiles() work?
    primarykey
    data
    text
    <p>I am writing a program that, when given a date, folder path, and file extension, will look into the folder and will go find all files that had a last access time from the beginning of the month to the current date, and only files with the file extension that was passed.</p> <p>The files that I am looking for are always in the same level in the folder tree so I can code into the program how far to dig to find the files.</p> <p>Currently my program takes about a minute for a day so today (The 16th) takes about sixteen and a half minutes.</p> <p>I want to make a program that fill find all files for a date range in a folder path and will extract information from the file. I just don't want to code how deep the program has to look in case my business changes how they store their files.</p> <p>I managed to make code that, if given a folder, the program will display the names of all the files for the date range but that took 25 minutes. Here is the code</p> <pre><code>TimeSpan BeginningTime = DateTime.Now.TimeOfDay; DateTime BeginningDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); DateTime EndingDate = DateTime.Now; string[] FoldersToLookAt = { @"e:\", @"e:\Kodak Images\", @"e:\images\", @"e:\AFSImageMerge\" }; foreach (string FolderPath in FoldersToLookAt) { for (DateTime Date = BeginningDate; Date &lt;= EndingDate; Date = Date.AddDays(1)) { string DateString = Date.ToString("yyMMdd"); string FilePath = (FolderPath + DateString); DirectoryInfo FilesToLookThrough = new DirectoryInfo(FilePath); if (FilesToLookThrough.Exists) { foreach (var MyFile in FilesToLookThrough.EnumerateFiles("*.dat", SearchOption.AllDirectories)) { if (MyFile.LastAccessTime &gt;= BeginningDate) { Console.WriteLine(MyFile.FullName); } } } } } </code></pre> <p>From what I see this first obtains all the files, then goes through all files and prints out all files that have a last access time greater than the beginning date.</p> <p>Is their a way in C# that will extract information from a file and NOT store it in a list? Or am I going to have to build the program from scratch?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload