private void ScanFolders() { string logFile = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "backup_BuildMasterFileList.txt"); string filters = string.Join(",", this.mediaBackup.Filters.ToArray()); this.mediaBackup.ClearFlags(); Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "Started."); foreach (string masterFolder in this.mediaBackup.MasterFolders) { Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "Scanning {0}", masterFolder); if (Directory.Exists(masterFolder)) { // Get the Freespace in GB long freeSpaceOnCurrentMasterFolder = Utils.GetDiskFreeSpace(masterFolder); Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "{0}GB free on {1}", freeSpaceOnCurrentMasterFolder, masterFolder); if (freeSpaceOnCurrentMasterFolder < this.mediaBackup.MinimumCriticalMasterFolderSpace) { Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, PushoverPriority.High, "Free space on {0} is too low", masterFolder); } foreach (string indexFolder in this.mediaBackup.IndexFolders) { string folderToCheck = Path.Combine(masterFolder, indexFolder); if (Directory.Exists(folderToCheck)) { Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "Scanning {0}", folderToCheck); string[] files = Utils.GetFiles( folderToCheck, filters, SearchOption.AllDirectories, FileAttributes.Hidden); foreach (string file in files) { // Log the file we're checking here #if DEBUG Utils.Log(logFile, "Checking {0}", file); #endif this.EnsureFile(file, masterFolder, indexFolder); } } } } else { Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, PushoverPriority.High, "{0} doesn't exist", masterFolder); } } this.mediaBackup.RemoveFilesWithFlag(false, true); this.mediaBackup.Save(); var totalFiles = this.mediaBackup.BackupFiles.Count(); long b = 0; DateTime oldestFileDate = DateTime.Today; BackupFile oldestFile = null; foreach (var a in this.mediaBackup.BackupFiles) { b += a.Length; if (a.BackupDiskChecked != null) { DateTime d = DateTime.Parse(a.BackupDiskChecked); if (d < oldestFileDate) { oldestFileDate = d; oldestFile = a; } } } Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "{0:n0} files at {1:n0}MB", totalFiles, b / 1024 / 1024); if (oldestFile != null) { Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "Oldest backup date is {0:n0} days ago at {1} for {2} on {3}", DateTime.Today.Subtract(oldestFileDate).Days, oldestFileDate.ToShortDateString(), oldestFile.GetFileName(), oldestFile.BackupDisk); } IEnumerable <BackupFile> filesNotOnBackupDisk = this.mediaBackup.BackupFiles.Where(p => string.IsNullOrEmpty(p.BackupDisk)); Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "{0:n0} files to backup", filesNotOnBackupDisk.Count()); IEnumerable <BackupFile> filesWithoutDiskChecked = this.mediaBackup.BackupFiles.Where(p => string.IsNullOrEmpty(p.BackupDiskChecked)); Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "{0:n0} files without DiskChecked set", filesWithoutDiskChecked.Count()); Utils.LogWithPushover(this.mediaBackup.PushoverUserKey, this.mediaBackup.PushoverAppToken, logFile, BackupAction.ScanFolders, "Completed."); }