示例#1
0
        public static void Run(string Dirname, Opts opts, ref Stats stats, ref bool CrtlC_pressed, Action<string> OutputHandler, Action<int, string> ErrorHandler, Action<string> ProgressCallback)
        {
            Spi.IO.StatusLineWriter StatusWriter = new Spi.IO.StatusLineWriter();

            foreach (var entry in Spi.IO.Directory.Entries(Dirname, ErrorHandler, opts.FollowJunctions))
            {
                if (CrtlC_pressed)
                {
                    break;
                }

                if (entry.isDirectory)
                {
                    stats.AllDirs += 1;
                    if (ProgressCallback != null)
                    {
                        ProgressCallback(entry.Dirname);
                    }
                    continue;
                }

                stats.AllBytes += entry.Filesize;
                stats.AllFiles += 1;

                bool PrintEntry = (opts.Pattern == null) ? true : Regex.IsMatch(entry.Filename, opts.Pattern);
                if (PrintEntry)
                {
                    stats.MatchedBytes += entry.Filesize;
                    stats.MatchedFiles += 1;
                    HandleMatchedFile(entry, opts.FormatString, OutputHandler);
                }
            }
        }
示例#2
0
        static Opts GetOpts(string[] args)
        {
            Opts opts = new Opts();
            var p = new Mono.Options.OptionSet() {
                { "r|rname=",   "regex applied to the filename",         v => opts.Pattern = v },
                { "o|out=",     "filename for result of files (UTF8)",   v => opts.OutFilename = v },
                { "p|progress", "prints out the directory currently scanned for a little progress indicator",   v => opts.progress = (v != null) },
                //{ "v", "increase debug message verbosity",                      v => { if (v != null) ++verbosity; } },
                { "h|help",     "show this message and exit",            v => opts.show_help = v != null },
                { "f|format=",  "format the output",                     v => opts.FormatString = v },
                { "j|follow",   "follow junctions",                      v => opts.FollowJunctions = (v != null) }
            };
            try
            {
                opts.Dirs = p.Parse(args);

                if (!String.IsNullOrEmpty(opts.Pattern))
                {
                    Console.Error.WriteLine("pattern parsed for rname [{0}]", opts.Pattern);
                }
                if (!String.IsNullOrEmpty(opts.FormatString))
                {
                    Console.Error.WriteLine("FormatString [{0}]", opts.FormatString);
                }
                if (opts.Dirs.Count() == 0)
                {
                    opts.Dirs.Add(Directory.GetCurrentDirectory());
                }
            }
            catch (Mono.Options.OptionException oex)
            {
                Console.WriteLine(oex.Message);
                return null;
            }
            if (opts.show_help)
            {
                ShowHelp(p);
                return null;
            }
            return opts;
        }