private void ZipFilesInDateRange(ArchiveArgs args, string archiveZipSearchPattern) { var total = new List <string>(Directory.GetFiles(CurrentDirectory, archiveZipSearchPattern)).Count(); var filePathsToZip = new List <string>(Directory.GetFiles(CurrentDirectory, archiveZipSearchPattern)) .Select(f => new { FilePath = f, FileDateTime = DateTimeFromFile(f) }) .OrderByDescending(f => f.FileDateTime) .Where(f => f.FileDateTime.Date >= args.Start.Date && f.FileDateTime.Date <= args.End) .Select(f => f.FilePath); var test = new List <string>(Directory.GetFiles(CurrentDirectory, archiveZipSearchPattern)) .Select(f => new { FilePath = f, FileDateTime = DateTimeFromFile(f) }) .OrderByDescending(f => f.FileDateTime) .Where(f => f.FileDateTime.Date >= args.Start.Date && f.FileDateTime.Date <= args.End) .Select(f => f).ToList(); long bytesZipped = 0; int count = 0; foreach (var file in filePathsToZip) { count++; if (FileIo.IsFileLocked(new FileInfo(file))) { continue; } ZipAFile(file, Path.GetFileName(file), ZippedFullFileName, true); if (ArchiveArgs.IgnoreFileSizeLimits >= args.MaxArchiveSizeBytes) { continue; } var fileInfo = new FileInfo(file); bytesZipped += fileInfo.Length; if (bytesZipped <= args.MaxArchiveSizeBytes) { continue; } CreateEmptyFileInZip("FileSizeLimitReached.txt", ZippedFullFileName); break; } if (!System.IO.File.Exists(ZippedFullFileName)) { CreateEmptyFileInZip("noLogs.txt", ZippedFullFileName); } }