A Repasky

A Repasky

  • NA
  • 231
  • 183.3k

Getting dynamically the directory and files under that directory.

Jun 14 2012 3:12 PM
I have to get all the files under a directory, but the directory name changes (uses the date).  Then I have to get all the txt files under it.  How can I do this dynamically using FileInfo?

Here is code that I have.

            List<string> fileList = new List<string>();
            DirectoryInfo di = new DirectoryInfo(@"E:\Data\CommercialEOB\MRDF\");
                        FileInfo[] fi = di.GetFiles("*.txt");
            if (fi.Length != 0)
            {
               foreach (FileInfo file in fi)
               {
                  Console.WriteLine(file);
                  mc.MRDF = file.ToString();
                  mc.logPath = @"C:\temp";
                  mc.Run();
               }
            }
            else
            {
               throw new Exception("No File Exists "new Exception());
            }
         }






Thanks,

arep

Answers (2)