private void GetFolderInfo(string path) { if (path.IsNullOrEmpty() || LocalFolder.GetIsExcludeFolder(path) || isCanceled) { return; } DirectoryInfo di = null; try { di = new DirectoryInfo(path); } catch (Exception ex) { LogHelper.DebugFormat("DirectoryInfo exception:{0}", ex.Message); return; } GetFolderInfo(di); }
private StatisticItem GetFolderInfo(DirectoryInfo dirInfo) { StatisticItem result = null; string folderPath = string.Empty; try { if (dirInfo.IsNull() || //Hard driver will be ignored by Attributes (dirInfo.Root.FullName != dirInfo.FullName && (LocalFolder.GetIsExcludeFolder(dirInfo.FullName) || LocalFolder.GetIsExcludeAttribute(dirInfo.Attributes))) || isCanceled) { return(result); } folderPath = dirInfo.FullName; } catch (Exception ex) { LogHelper.DebugFormat("GetFiles exception:{0},path={1}", ex.Message, dirInfo.Name); return(result); } StatisticItem folderItem = null; lock (this.lockDicObj) { folderItem = GetCacheItem(folderPath, cacheDic, true); } if (!folderItem.IsNull() && folderItem.IsCompleted) { return(folderItem); } folderItem = new StatisticItem(); folderItem.Path = folderPath; AddToCache(folderItem); bool isFolderCanceled = GetFolderIsCanceled(folderPath); FileInfo[] files = null; try { files = dirInfo.GetFiles(); if (!files.IsNullOrEmpty() && (folderItem.IsNull() || (!folderItem.IsNull() && !folderItem.IsCompleted))) { foreach (var fi in files) { if (isCanceled || isFolderCanceled) { return(result); } if (fi.IsNull() || CheckIsFileIgnored(fi)) { continue; } fileScannCount++; folderItem.ItemCount++; folderItem.Size += fi.Length; if (ReportProgressForFolder(folderPath)) { isFolderCanceled = GetFolderIsCanceled(folderPath); } } } } catch (Exception ex) { LogHelper.DebugFormat("GetFiles exception:{0}", ex.Message); } DirectoryInfo[] folders = null; try { folders = dirInfo.GetDirectories(); if (!folders.IsNullOrEmpty()) { foreach (var f in folders) { try { ///Folder too long path isFolderCanceled = GetFolderIsCanceled(f.FullName); ///Check is cancel for every folder if (isCanceled) { return(folderItem); } if (isFolderCanceled) { continue; } StatisticItem subItem = GetFolderInfo(f); } catch (Exception ex) { LogHelper.DebugFormat("GetDirectories exception:{0}", ex.Message); } } } } catch (Exception ex) { LogHelper.DebugFormat("GetDirectories exception:{0}", ex.Message); } if (!folderItem.IsNull()) { isFolderCanceled = GetAllFoldersIsCanceled(folderPath); if (!isFolderCanceled) { folderItem.IsCompleted = true; } result = folderItem; } return(folderItem); }