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
Posted Jun 15, 2012, 12:37 AM
Otherwise, you arrange the folders based on the name descending order. So, you'll get the latest folder name always in the top.
Then pick the Top 1 folder name and you can use your code.
string LatestFoldername = GetLatestFoldername("E:\Data\CommercialEOB\MRDF\")
List<string> fileList = new List<string>();
DirectoryInfo di = new DirectoryInfo(@"E:\Data\CommercialEOB\MRDF\" + LatestFoldername);
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());
}
}
private string GetLatestFoldername(string path)
{
1) Here you get all the sub-folders of the specified directory (path parameter)
2) Sort the folder names based on the name / folder created date time decending order.
3) Pick up the top 1 folder name and return that top 1 folder name.
}
Hope this helps you.
A RepaskyPosted Jun 15, 2012, 8:50 AM
arep