static void DirectoryBuilder(DirectoryIterator sender, DirectoryIterator.Args args) { Options options = (Options)sender.Tag; string dirName = PathUtility.GetBaseName(sender.Path, args.Path); string newTargetPath = Path.Combine(options.TargetPath, dirName); Directory.CreateDirectory(newTargetPath); if (options.Verbose) { Console.WriteLine("'{0}' directory created", dirName); } }
static void FileSystemObjectPrinter(DirectoryIterator sender, DirectoryIterator.Args args) { string fsoName = PathUtility.GetBaseName(sender.Path, args.Path); if (args.IsDirectory) { Console.ForegroundColor = ConsoleColor.Blue; // If the filesystem object is a directory, we add a directory separator char // and change the color to blue (UNIX ls command default). Console.WriteLine("{0}{1}", fsoName, Path.DirectorySeparatorChar); Console.ResetColor(); } else { Console.WriteLine(fsoName); } }
static void FileSystemObjectPrinterVerbose(DirectoryIterator sender, DirectoryIterator.Args args) { //[d/-][a/-][r/-][h/-][s/-] StringBuilder builder = new StringBuilder(); FileAttributes attr = File.GetAttributes(args.Path); DateTime lwt; if (args.IsDirectory) { Console.ForegroundColor = ConsoleColor.Blue; builder.Append("d"); lwt = Directory.GetLastWriteTime(args.Path); } else { builder.Append("-"); lwt = File.GetLastWriteTime(args.Path); } if ((attr & FileAttributes.Archive) == FileAttributes.Archive) { builder.Append("a"); } else { builder.Append("-"); } if ((attr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { builder.Append("r"); } else { builder.Append("-"); } if ((attr & FileAttributes.Hidden) == FileAttributes.Hidden) { builder.Append("h"); } else { builder.Append("-"); } if ((attr & FileAttributes.System) == FileAttributes.System) { builder.Append("s"); } else { builder.Append("-"); } builder.Append(" "); //4 spaces builder.Append(lwt.ToShortDateString()); builder.Append(" "); //4 spaces if (!args.IsDirectory) { string ln = new FileInfo(args.Path).Length.ToString(CultureInfo.InvariantCulture); int ts = 10 - ln.Length; for (int i = 0; i < ts; i++) { builder.Append(' '); } builder.Append(ln); } else { builder.Append(" "); //10 spaces } builder.Append(" "); //4 spaces builder.Append(PathUtility.GetBaseName(sender.Path, args.Path)); if (args.IsDirectory) { builder.Append(PathUtility.DirectorySeparatorString); } builder.Append(" "); //4 spaces Console.WriteLine(builder.ToString()); Console.ResetColor(); }