Esempio n. 1
0
        CommandLineCode TraverseDirectory()
        {
            PreTraverse();

            using (var writer = new System.IO.StreamWriter(_arguments._output_filename, false, Encoding.UTF8))
            {
                var subFolders = DirectoryTraverser.SafeEnumerateFilesInAllDirectories(_arguments._search_path, _arguments._search_pattern);
                var counter    = 0;
                //サブフォルダを列挙する
                foreach (string subFolder in subFolders)
                {
                    string sub_dir = FormatDirectoryName(subFolder);
                    string abs_dir = System.IO.Path.Combine(_arguments._working_directory, sub_dir);
                    writer.WriteLine(string.Format("{0}\t{1}\t{2}", sub_dir, "@action_directory", abs_dir));
                    if (_arguments._delay != 0)
                    {
                        //(memo) デバッグ用途なのでディスクへ書き込まれるようにする。
                        writer.Flush();
                        Thread.Sleep(_arguments._delay);
                    }

                    if (counter == 10)
                    {
                        //はじめの10行はすぐにファイルへ書き出す
                        writer.Flush();
                    }
                    ++counter;
                }
            }
            return(CommandLineCode.Success);
        }
Esempio n. 2
0
        static IEnumerable <Result> SafeEnumerateFilesInAllFilesMain(string path, string abs_root_path, string searchPattern)
        {
            {
                IEnumerable <FileInfo> files = null;

                try
                {                //ファイルを返す
                    var di = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(path));
                    files = di.EnumerateFiles(searchPattern, System.IO.SearchOption.TopDirectoryOnly);
                }
                catch (System.UnauthorizedAccessException)
                {
                    //pass
                }

                if (files != null)
                {
                    foreach (var f in files)
                    {
                        if (UseThisFile(f.FullName, f.Attributes))
                        {
                            yield return(new Result(GetRelativePath(abs_root_path, f.FullName), f.FullName));
                        }
                    }
                }
            }

            string[] sub_dirs = null;
            try
            {
                sub_dirs = System.IO.Directory.GetDirectories(path, "*", System.IO.SearchOption.TopDirectoryOnly);
            }
            catch (System.UnauthorizedAccessException)
            {
                //pass
            }

            if (sub_dirs != null)
            {
                foreach (var dir in sub_dirs)
                {
                    if (!DirectoryTraverser.UseThisFolder(dir))
                    {
                        continue;
                    }
                    foreach (var o in SafeEnumerateFilesInAllFilesMain(dir, abs_root_path, searchPattern))
                    {
                        yield return(o);
                    }
                }
            }
        }