/// Copyright(c) 2016 pakkin. All Rights Reserved. /// [改訂履歴] /// 2016.01.15 作成 using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace ConsoleApplication1 { class Program { private static ArrayList entries; private static void SearchEntries(string path, String tree = null) { if (tree == null) { entries = new ArrayList(); entries.Add("ROOT : " + path); SearchEntries(path, ""); return; } string[] fils = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly); string[] dirs = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); for (int i = 0; i < fils.Length; i++) fils[i] = Path.GetFileName(fils[i]); for (int i = 0; i < dirs.Length; i++) dirs[i] = Path.GetFileName(dirs[i]); if (fils.Length > 1) Array.Sort(fils); if (dirs.Length > 1) Array.Sort(dirs); for (int i = 0; i < fils.Length + dirs.Length; i++) { string type = (i < fils.Length ? "F" : "D") + (tree.Length + 1).ToString("000"); string enti = i < fils.Length ? fils[i] : dirs[i - fils.Length]; string curr = i == fils.Length + dirs.Length - 1 ? "└" : "├"; string next = i == fils.Length + dirs.Length - 1 ? " " : "|"; entries.Add(type + " : " + tree + curr + enti); if (i >= fils.Length) SearchEntries(path + @"\" + enti, tree + next); } } static void Main(string[] args) { SearchEntries(@"C:\Program Files\WinMerge"); Console.Write(string.Join(Environment.NewLine, entries.ToArray())); Console.ReadKey(); } } }
Copyright(c) 2014-2022 pakkin. All Rights Reserved.