Guest User

Untitled

a guest
Dec 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace list_of_files
  5. {
  6. class Program
  7. {
  8.  
  9. private static void FilesandFolders(string Path1, int Level = 0)
  10. {
  11. string[] directory = Directory.GetDirectories(Path1);
  12. string[] set = Directory.GetFiles(Path1);
  13.  
  14. try
  15. {
  16. foreach (string file in set)
  17. {
  18. Console.WriteLine("└" + Path.GetFileNameWithoutExtension(file));
  19. }
  20.  
  21. foreach (string file in directory)
  22. {
  23. Console.WriteLine("+" + Path.GetFileNameWithoutExtension(file));
  24. FilesandFolders(file, Level++);
  25. }
  26. }
  27. catch { }
  28. }
  29.  
  30. static void Main()
  31. {
  32. Console.WriteLine("Программа выводит каталог папок и файлов в заданной папке.");
  33. Console.Write("Введите имя папки: ");
  34. string path = Console.ReadLine();
  35. Console.Read();
  36. }
  37. }
  38. }
  39.  
  40. class Program
  41. {
  42.  
  43. private static void FilesandFolders(string Path1, int down = 0)
  44. {
  45. string[] directory = Directory.GetDirectories(Path1);
  46. string[] set = Directory.GetFiles(Path1);
  47. try
  48. {
  49. foreach (string file in set)
  50. {
  51. Console.WriteLine(new string(' ', down) + " └ " + Path.GetFileNameWithoutExtension(file));
  52. }
  53. foreach (string file in directory)
  54. {
  55. Console.WriteLine(new string(' ', down) + " + " + Path.GetFileNameWithoutExtension(file));
  56. FilesandFolders(file, down++);
  57. }
  58. }
  59. catch { }
  60. }
  61. static void Main()
  62. {
  63. Console.WriteLine("Программа выводит каталог папок и файлов в заданной папке.");
  64. Console.Write("Введите имя папки: ");
  65. string path = Console.ReadLine();
  66. Console.WriteLine(" " + path);
  67. FilesandFolders(path, 0);
  68. Console.Read();
  69. }
  70.  
  71. private static void SearchFoldersAndFiles(String path, DirectoryInfo parent = null, String space = null)
  72. {
  73. DirectoryInfo directoryInfo = new DirectoryInfo(path);
  74.  
  75. foreach (var item in directoryInfo.GetDirectories())
  76. {
  77. Console.WriteLine($"t{space}+{item.Name}");
  78. SearchFoldersAndFiles(path + @"" + item.Name, item.Parent, "t");
  79. foreach (var file in item.GetFiles())
  80. {
  81. Console.WriteLine($"tt└{file.Name}");
  82. }
  83. Console.WriteLine();
  84. }
  85. }
  86.  
  87. static void Main(string[] args)
  88. {
  89. Console.WriteLine("Программа выводит каталог папок и файлов в заданной папке.");
  90. Console.Write("Введите имя папки: ");
  91. string path = Console.ReadLine();
  92. Console.WriteLine(" " + path);
  93. SearchFoldersAndFiles($@"{path}", null);
  94. Console.ReadKey();
  95. }
Add Comment
Please, Sign In to add comment