private IEnumerable<DateAndSequenceArchive> FindDateAndSequenceArchives(string dirName, string logFileName,
string fileNameMask,
int minSequenceLength, string dateFormat, FileNameTemplate fileTemplate)
{
var directoryInfo = new DirectoryInfo(dirName);
int archiveFileNameMinLength = fileNameMask.Length + minSequenceLength;
var archiveFileNames = GetFiles(directoryInfo, fileNameMask)
.Where(n => n.Name.Length >= archiveFileNameMinLength)
.OrderBy(n => n.CreationTime)
.Select(n => n.FullName);
foreach (string archiveFileName in archiveFileNames)
{
//Get the archive file name or empty string if it's null
string archiveFileNameWithoutPath = Path.GetFileName(archiveFileName) ?? "";
DateTime date;
int sequence;
if (
!TryParseDateAndSequence(archiveFileNameWithoutPath, dateFormat, fileTemplate, out date,
out sequence))
{
continue;
}
//It's possible that the log file itself has a name that will match the archive file mask.
if (string.IsNullOrEmpty(archiveFileNameWithoutPath) ||
archiveFileNameWithoutPath.Equals(Path.GetFileName(logFileName)))
{
continue;
}
yield return new DateAndSequenceArchive(archiveFileName, date, dateFormat, sequence);
}
}