vstoyanov

PFS altorithm

Apr 8th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5.  
  6. namespace BashSoft
  7. {
  8. public static     class IOManager
  9.     {
  10.         public static void TraverseDirectory(string path)
  11.         {
  12.            
  13.             OutputWritter.WriteEmptyLine();
  14.             int initialIdentation = path.Split('\\').Length;
  15.             Queue<string> subFolders = new Queue<string>();
  16.             subFolders.Enqueue(path);
  17.  
  18.             var subdirectory = Directory.GetDirectories(path);
  19.  
  20.          
  21.            
  22.  
  23.             OutputWritter.WriteOnNewLine(subFolders.Dequeue());
  24.  
  25.             foreach (var item in subdirectory)
  26.             {
  27.                 subFolders.Enqueue(item);
  28.             }
  29.  
  30.  
  31.             while (subFolders.Count !=0)
  32.             {
  33.          
  34.                
  35.  
  36.                 string currentPath = subFolders.Dequeue();
  37.                 int identation = currentPath.Split('\\').Length - initialIdentation;
  38.  
  39.  
  40.                 var tempDir = Directory.GetDirectories(currentPath);
  41.  
  42.                 if (tempDir.Length > 0)
  43.                 {
  44.                     subFolders.Enqueue(tempDir[0]);
  45.                     OutputWritter.WriteOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));
  46.  
  47.                 }
  48.                 else
  49.                 {
  50.                     OutputWritter.WriteOnNewLine(string.Format("{0}{1}", new string('-', identation), currentPath));
  51.  
  52.  
  53.                 }
  54.                              
  55.                
  56.             }
  57.  
  58.            
  59.  
  60.              
  61.  
  62.  
  63.         }
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment