I have the following string
\\server\f$\direct1\205486060518032015-05-28 150931.rtf
Which contains a date in the format yyyy-MM-dd hhmmss
Now I have managed to extract that string using a Regular Expression
Regex rgx = new Regex(@"\d{4}-\d{2}-\d{2} \d{6}");
di = new DirectoryInfo(Location);
var fileList = di.GetFiles("*.*", SearchOption.TopDirectoryOnly);
foreach (FileInfo fi in fileList)
{
EngineEvent(this, new EngineEventProperties(String.Format("Filename: {0}", fi.FullName)));
DateTime fileDate = DateTime.Now;
Match mat = rgx.Match(fi.FullName);
.
.
.
}
The Match contains the expected string '2015-05-28 150931'
However when I try and use the following code to convert it to a DateTime
if (DateTime.TryParseExact(fi.FullName, "yyyy-MM-dd hhmmss", CultureInfo.InvariantCulture, DateTimeStyles.None, out fileDate))
{
Console.WriteLine("Date : {0}", fileDate);
};
It returns false, using ParseExact fails saying the string does not contain a date.
So how can I do the conversion?