How to get the latest file in the directory based up on the creation time using vc#.net

public static void GetlatestFilesList(String DirPath)
{
DirectoryInfo di = new DirectoryInfo(DirPath);
if (di.Exists)
{
FileInfo[] rgFiles = di.GetFiles(SearchPattern, SearchOption.TopDirectoryOnly);
//Sort the file based upon the creation time
int i,j;
for (i = 0; i < j =" 0;"> rgFiles[j].CreationTime)
{
FileInfo fiTmp = rgFiles[i];
rgFiles[i] = rgFiles[j];
rgFiles[j] = fiTmp;
}
}
}
//Based upon the latest file we need to read the data
foreach (FileInfo fi in rgFiles)
{
Console.WriteLine("FileName" + fi.Name + " Creation Time" + fi.CreationTime);
}
}
else
{
Console.WriteLine("Could not find the Directory: {0}.", DirPath);
}
}

Comments

Popular posts from this blog

IBM FileNet: Bulk Processing using JavaScript

DB2 Date Time Functions

File Net Insert Document