private static int CountFiles(bFolderInfo folderInfo) { int count = folderInfo.Files.Count; foreach (bFolderInfo folder in folderInfo.Folders) { count += folder.CountFiles(); } return count; }
public static bFileInfo CreateFileInfo(FileInfo fileInfo, int hashingSize, bFolderInfo folderInfo) { try { bFileInfo bfi = new bFileInfo(); bfi.Name = fileInfo.Name; bfi.Size = fileInfo.Length; bfi.DateTime = fileInfo.LastWriteTime; bfi.Hash = CalcHash(fileInfo, hashingSize); bfi.ParentFolderCode = folderInfo.Code; return bfi; } catch { return null; } }
public bFolderInfo ScanFolder(string folder, bFolderInfo parentFolder) { SendProgressString(folder); bFolderInfo folderInfo = new bFolderInfo(); folderInfo.Code = Guid.NewGuid().ToString(); folderInfo.ParentFolderCode = parentFolder == null ? null : parentFolder.Code; folderInfo.Title = Path.GetDirectoryName(folder); DirectoryInfo di = new DirectoryInfo(folder); foreach (FileInfo fileInfo in di.GetFiles(FileMasks)) { bFileInfo bfi = CreateFileInfo(fileInfo, HashingSize, folderInfo); if (bfi == null) continue; folderInfo.Files.Add(bfi); } if (ScanSubfolders) { foreach (DirectoryInfo directoryInfo in di.GetDirectories("*.*")) { folderInfo.Folders.Add(ScanFolder(directoryInfo.FullName, folderInfo)); } } return folderInfo; }