private static void ProcessFile(FolderNode parent, string[] path, int index) { string currentPath = path[index]; // The last part of the path should be the filename. if (path.Length - 1 == index) { var fileNode = new FileNode(currentPath); parent.AddChild(fileNode); return; } // Check if the current folder exists to prevent duplicates. var node = FindFolderNode(parent, currentPath); if (node == null) { node = new FolderNode(currentPath); parent.AddChild(node); } ProcessFile(node, path, index + 1); }
private void ReadNative(Queue <FolderState> subdirs, CancellationToken token) { Win32FindData find = new Win32FindData(); FolderState folderState = subdirs.Dequeue(); ScanningState state = folderState.State; FolderNode parent = folderState.Folder; bool findResult; string parentPath = parent.Path; string searchPattern = PathUtils.CombineNoChecks(parentPath, "*"); if (!searchPattern.StartsWith(@"\\?\")) { searchPattern = @"\\?\" + searchPattern; } IntPtr hFind = FindFirstFileEx(searchPattern, FindExInfoLevels.Basic, out find, FindExSearchOps.NameMatch, IntPtr.Zero, FindExFlags.LargeFetch); if (hFind == InvalidHandle) { return; } FolderNode fileCollection = null; FileNodeBase singleFile = null; try { do { string filePath = PathUtils.CombineNoChecks(parentPath, find.cFileName); if (find.IsRelativeDirectory || SkipFile(state, find.cFileName, filePath)) { // Skip these types of entries findResult = FindNextFile(hFind, out find); continue; } FileNodeBase child; if (find.IsDirectory) { FolderNode folder = new FolderNode(find); child = folder; if (!find.IsSymbolicLink) { subdirs.Enqueue(new FolderState(folder, state)); } } else { FileNode file = new FileNode(find); child = file; if (!find.IsSymbolicLink) { state.ScannedSize += child.Size; totalScannedSize += child.Size; } file.extRecord = extensions.Include(GetExtension(file.Name), child.Size); } parent.AddChild(child, ref fileCollection, ref singleFile); SuspendCheck(); if (token.IsCancellationRequested) { return; } findResult = FindNextFile(hFind, out find); } while (findResult); //if (parent.IsWatched) // parent.RaiseChanged(FileNodeAction.ChildrenDone); } finally { FindClose(hFind); } }