public override void Scan() { BlockPerfStats stats = new BlockPerfStats(); stats.Begin(); Results = new PathScanResults <string>(); // // Add sources. // foreach (var entry in Plan.SelectedSources) { try { switch (entry.Type) { default: throw new InvalidOperationException("Unhandled EntryType"); case EntryType.DRIVE: { var dir = new ZetaLongPaths.ZlpDirectoryInfo(new DriveInfo(entry.Path).RootDirectory.FullName); AddDirectory(dir); break; } case EntryType.FOLDER: { var dir = new ZetaLongPaths.ZlpDirectoryInfo(entry.Path); AddDirectory(dir); break; } case EntryType.FILE: { var file = new ZetaLongPaths.ZlpFileInfo(entry.Path); AddFile(file); break; } } } catch (OperationCanceledException) { throw; // Rethrow! } catch (Exception ex) { HandleException(entry.Type, entry.Path, ex); } } stats.End(); }
private void AddFile(ZetaLongPaths.ZlpFileInfo file) { CancellationToken.ThrowIfCancellationRequested(); try { // IMPORTANT: The condition below, `if (!file.Exists)`, doesn't guarantee the // file will exist after this statement! We probably shouldn't try to detect this but // handle any exceptions that may be raised. if (!file.Exists) { // FileInfo.FullName may throw: // System.IO.PathTooLongException // System.Security.SecurityException logger.Warn("File {0} does not exist", file.FullName); return; } var item = file.FullName; // IMPORTANT: Strip the \\?\ prefix Windows uses for long paths (those > MAX_PATH). if (item != null && item.StartsWith(@"\\?\")) { item = item.Substring(4); } Results.AddedFile(item); if (FileAdded != null) { FileAdded(this, item); } } catch (OperationCanceledException) { throw; // Rethrow! } catch (Exception ex) { HandleException(EntryType.FILE, file.FullName, ex); } }
public static string UnsafeGetDirectoryName(string filePath) { ZetaLongPaths.ZlpFileInfo file = new ZetaLongPaths.ZlpFileInfo(filePath); return(file.DirectoryName); }