C# File Last Modified time

I am trying to get the last write time of a particular file. This is the code and it works:`

DirectoryInfo DR = new DirectoryInfo(folderPath);  
FileInfo[] FR2 = DR.GetFiles("InputData.csv");
var FileLastModified= null;

foreach (FileInfo F1 in FR2)
{
    FileLastModified = F1.LastWriteTime;
}

FileLastModified gives me the last write time and I am only interested to find the time of this InputData.csv file. The problem is I do not want to use a for loop and need the write time for just one particular file. Is there a better way to write this without the loop?

Jon Skeet
people
quotationmark

You don't have to search through a directory to get a FileInfo - you can construct one directly from the full path. It sounds like you just need:

var fileInfo = new FileInfo(Path.Combine(folderPath, "InputData.csv"));
var lastModified = fileInfo.LastWriteTime;

people

See more on this question at Stackoverflow