public List<MovieFileContents> GetDirFiles(string myPathname, bool myIsJpegOnly) { if (!Directory.Exists(myPathname)) return null; // 1行でJPGファイルを除いたリストを取得できていたが、正常に動作しなくなったので、下のループlistFilesへのAddを使用 //IEnumerable<string> files = from file in Directory.GetFiles(@strDir) where regex.IsMatch(file) select file; string[] files = Directory.GetFiles(myPathname); Regex regex; if (myIsJpegOnly) regex = new Regex(MovieFileContents.REGEX_JPEG_EXTENTION); else regex = new Regex(MovieFileContents.REGEX_MOVIE_EXTENTION); List<string> listFiles = new List<string>(); foreach (var file in files) { FileInfo fileinfo = new FileInfo(file.ToString()); if (regex.IsMatch(fileinfo.Name.ToLower())) { TotalLength = TotalLength + fileinfo.Length; FileCount++; listFiles.Add(file.ToString()); } } //var files = Directory.GetFiles(@"Z:\DVDRip", "*jpg;*avi", SearchOption.TopDirectoryOnly); List<MovieFileContents> listMContents = new List<MovieFileContents>(); List<string> listManyFileCheck = new List<string>(); foreach (var file in listFiles) { FileInfo fileinfo = new FileInfo(file.ToString()); string ExtWithoutName = fileinfo.Name.Replace(fileinfo.Extension, ""); bool isManyFileExist = false; foreach (string data in listManyFileCheck) { if (ExtWithoutName.IndexOf(data) >= 0) { isManyFileExist = true; break; } } if (isManyFileExist) continue; MovieFileContents fileData = new MovieFileContents(); fileData.Name = ExtWithoutName; fileData.Extension = fileinfo.Extension.Replace(".", "").ToUpper(); fileData.Label = myPathname; fileData.FileDate = fileinfo.LastWriteTime; fileData.FileCount = 1; fileData.Size = fileinfo.Length; fileData.Parse(); // サムネイル画像を見るを追加する string FileExt = ""; FileExt = fileinfo.Extension; if (FileExt.Length > 0) { string ThumbnailFilename = fileinfo.FullName.Replace(FileExt, "") + "_th.jpg"; if (File.Exists(ThumbnailFilename)) { fileData.IsExistsThumbnail = true; } } Regex regexManyFile = new Regex("_[0-9]$"); if (regexManyFile.IsMatch(ExtWithoutName)) { MovieFileContents data = new MovieFileContents(); string FilesPattern = Regex.Replace(fileinfo.Name, "_[0-9]\\" + fileinfo.Extension + "$", "*" + fileinfo.Extension); string[] arrFiles = System.IO.Directory.GetFiles(fileinfo.Directory.FullName, FilesPattern, SearchOption.TopDirectoryOnly); if (arrFiles != null && arrFiles.Length > 1) { listManyFileCheck.Add(Regex.Replace(ExtWithoutName, "_[0-9]$", "")); long size = 0; foreach (string pathname in arrFiles) { FileInfo fileinfoMany = new FileInfo(pathname); size += fileinfoMany.Length; } fileData.Name = Regex.Replace(fileinfo.Name, "_[0-9]\\" + fileinfo.Extension + "$", ""); fileData.Size = size; fileData.FileCount = arrFiles.Length; } } listMContents.Add(fileData); } return listMContents; }
public List<MovieFileContents> BackupGetDirFiles(string myPathname) { //////////////////////////////// //////////// バックアップ ///////////////////////////////// /////////////////// if (!Directory.Exists(myPathname)) return null; // 1行でJPGファイルを除いたリストを取得できていたが、正常に動作しなくなったので、下のループlistFilesへのAddを使用 //IEnumerable<string> files = from file in Directory.GetFiles(@strDir) where regex.IsMatch(file) select file; string[] files = Directory.GetFiles(myPathname); Regex regex = new Regex(MovieFileContents.REGEX_MOVIE_EXTENTION); List<string> listFiles = new List<string>(); foreach (var file in files) { FileInfo fileinfo = new FileInfo(file.ToString()); if (regex.IsMatch(fileinfo.Name.ToLower())) { TotalLength = TotalLength + fileinfo.Length; FileCount++; listFiles.Add(file.ToString()); } } //var files = Directory.GetFiles(@"Z:\DVDRip", "*jpg;*avi", SearchOption.TopDirectoryOnly); List<MovieFileContents> listMContents = new List<MovieFileContents>(); foreach (var file in listFiles) { FileInfo fileinfo = new FileInfo(file.ToString()); MovieFileContents data = new MovieFileContents(); data.Name = fileinfo.Name; data.Label = myPathname; data.FileDate = fileinfo.LastWriteTime; data.Size = fileinfo.Length; data.Parse(); // サムネイル画像を見るを追加する string FileExt = ""; FileExt = fileinfo.Extension; if (FileExt.Length > 0) { string ThumbnailFilename = fileinfo.FullName.Replace(FileExt, "") + "_th.jpg"; if (File.Exists(ThumbnailFilename)) { data.IsExistsThumbnail = true; } } listMContents.Add(data); } return listMContents; }