public static int CleanUpOriginalWallpaper() { var count = 0; var originalFileList = OriginalWallpaperDirectory.GetFiles("*", SearchOption.AllDirectories); foreach (var currentOriginalFile in originalFileList) { if (WallpaperFileHelper.IsImage(currentOriginalFile)) { bool fileFound = false; foreach (var currentWallpaper in Wallpapers) { if (WallpaperFileHelper.ImageFilesMatch(currentWallpaper.File, currentOriginalFile)) { fileFound = true; break; } } if (!fileFound) { currentOriginalFile.MoveTo(Path.Combine(TrashDirectory.FullName, currentOriginalFile.Name)); count++; } } } return(count); }
internal static List <FileInfo> SortOutOrignals() { var movedFiles = new List <FileInfo>(); //Go through all original files and see if they are not listed in the other folder. (O(n)) var allOriginalFiles = OriginalWallpaperDirectory.GetFiles("*", SearchOption.AllDirectories); foreach (var currentFile in allOriginalFiles) { if (WallpaperFileHelper.IsImage(currentFile)) { if (currentFile.Name.Contains("#o")) { //Check if there is a corresponding wallpaper file var correspondingFileName = Path.GetFileNameWithoutExtension(currentFile.FullName).Replace("#o", "#"); var files = new[] { $"{correspondingFileName}.png", //Test for png $"{correspondingFileName}.jpg", //Test for jpg }; var foundFile = files.FirstOrDefault(file => System.IO.File.Exists(Path.Combine(WallpaperDirectory.FullName, currentFile.Directory.Name, file))); //Find the first path that exits if (foundFile is null) { //Move file, it does not belong here currentFile.MoveTo(Path.Combine(TrashDirectory.FullName, currentFile.Name)); movedFiles.Add(currentFile); } } } } return(movedFiles); }