private static SemiAutoSaveFileAttr GetAttr(string path)
{
string fileName = Path.GetFileName(path);
const int DATE_TIME_LENGTH = 14;
if (fileName == null || fileName.Count() <= DATE_TIME_LENGTH + 1)
{
return null;
}
if (!fileName.Contains(".") || fileName.IndexOf(".") == 0)
{
return null;
}
string dateStr = fileName.Substring(fileName.Count() - DATE_TIME_LENGTH, DATE_TIME_LENGTH);
DateTime date;
if (!DateTime.TryParseExact(dateStr, "yyyyMMddHHmmss", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out date))
{
return null;
}
string fileNameWithoutExtension = fileName.Substring(0, fileName.IndexOf("."));
return new SemiAutoSaveFileAttr() { CreatedDate = date, FileName = fileNameWithoutExtension, FullPath = path };
}