Esempio n. 1
0
        static void ReportIterateError(DirectoryIterator dirIter)
        {
            Exception ex = dirIter.LastException;

            if (ex != null)
            {
                ReportError(ex.Message);
            }
        }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 static bool ExecuteIterator(Options options, DirectoryIterator.Delegate callback, bool processFiles)
 {
     bool hasError = false;
     DirectoryIterator dirIter = new DirectoryIterator(options.SourcePath);
     dirIter.ProcessFiles = processFiles;
     dirIter.Tag = options;
     if (!dirIter.Iterate(callback))
     {
         ReportIterateError(dirIter);
         hasError = true;
     }
     return hasError;
 }
 private static void PrintDirsAndFiles(DirectoryIterator sender, DirectoryIterator.Args args)
 {
     string text;
     if (args.IsDirectory)
     {
         text = "DIR: {0}";
     }
     else
     {
         text = "FILE: {0}";
     }
     Console.WriteLine(text, args.Path);
 }
Esempio n. 6
0
        static bool ExecuteIterator(Options options, DirectoryIterator.Delegate callback, bool processFiles)
        {
            bool hasError             = false;
            DirectoryIterator dirIter = new DirectoryIterator(options.SourcePath);

            dirIter.ProcessFiles = processFiles;
            dirIter.Tag          = options;
            if (!dirIter.Iterate(callback))
            {
                ReportIterateError(dirIter);
                hasError = true;
            }
            return(hasError);
        }
Esempio n. 7
0
 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);
     }
 }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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();
        }
Esempio n. 10
0
 public bool Iterate(DirectoryIterator.Delegate directoryIteratorDelegate)
 {
     bool hasError = false;
     this._callback = directoryIteratorDelegate;
     try
     {
         if (File.Exists(this._path))
         {
             ProcessFile(this._path);
         }
         else if (Directory.Exists(this._path))
         {
             ProcessDirectory(this._path);
         }
     }
     catch (UnauthorizedAccessException uaex)
     {
         this._lastException = uaex;
         hasError = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return !hasError;
 }
Esempio n. 11
0
        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();
        }
Esempio n. 12
0
 static void ReportIterateError(DirectoryIterator dirIter)
 {
     Exception ex = dirIter.LastException;
     if (ex != null)
     {
         ReportError(ex.Message);
     }
 }
Esempio n. 13
0
 public void IterateDirsToConsole()
 {
     DirectoryIterator dirIter = new DirectoryIterator(_testPath);
     dirIter.Iterate(delegate(DirectoryIterator sender, DirectoryIterator.Args args) { Console.WriteLine(args.Path); });
 }
Esempio n. 14
0
 public void IterateAllToConsole()
 {
     DirectoryIterator dirIter = new DirectoryIterator(_testPath);
     dirIter.ProcessFiles = true;
     dirIter.Iterate(new DirectoryIterator.Delegate(PrintDirsAndFiles));
 }