First of all, I have a list of file name in ftp server:
20130612_00
20130612_06
20130612_12
In Main(), i have something like this
Public Main()
{
//function to download all file from ftp server to local directory
DownLoadFileFromFTP();
//function to open the latest file in the local directory
OpenLatestFileInLocal();
}
I want to have a function to check the latest file based on the file name in local directory. In this case, the latest file will be 20130612_12
My idea is to first remove the special character and get only the digit number and I am having a list<int>
like this now:
2013061200
2013061206
2013061212
Hence, if i check the max value inside the list<int>
, I will get to know which one is the latest file.
My ultimate objective is to open the latest file by executing OpenTxtFile(string fileName)
Hence, I have a function something like below:
private void OpenLatestFileInLocal()
{
// Get list of fileName from local directory
// Ouput fileList_str = (string){20130612_00 , 20130612_06, 20130612_12}
List<string> fileList_str = Directory.EnumerateFiles(localDir, "*.txt", SearchOption.AllDirectories).Select(Path.GetFileName).ToList();
foreach (string fileName in fileList_str)
{
fileLIst_int.Add(Convert.ToInt32(RemoveSpecialCharacters(fileName)));
}
// Ouput: fileList_int = (int){2013061200 , 2013061206, 2013061212}
int Latest = fileLIst_int.Max(); //Output: Latest = 2013061212
// Problem is here.. my OpenTextFile function need to pass the fileName in string
// But I identify the latest file as an (int) as 2013061212
// I need to know 2013061212 is actually 20130612_12.txt
// so that, I can pass the fileName into OpenTxtFile(string fileName)
OpenTxtFile(fileName_Latest);
}
private void OpenTextFile(string fileName)
{
// this function will only open file based on string fileName in local directory
}