Last active
September 28, 2016 15:51
-
-
Save olecksamdr/b5518f2ee9fde17318df19228075959d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Text; | |
class directoryTree { | |
static int nestingLevel = 0; | |
static void printSpaces(int n) { | |
n *= 3; | |
for (; n > 0; n--) { | |
Console.Write(' '); | |
} | |
} | |
static void printFilesInDir(DirectoryInfo dirInf) { | |
foreach (FileInfo file in dirInf.GetFiles()) { | |
printSpaces(nestingLevel); | |
Console.Write(file.Name + "\n"); | |
} | |
} | |
static void traceDirectoryTree(DirectoryInfo dirInfo) { | |
// Для того щоб не виводити поточний каталог, а лише його дочірні каталоги | |
if (nestingLevel > 0) { | |
printSpaces(nestingLevel); | |
Console.ForegroundColor = ConsoleColor.Cyan; | |
Console.Write(dirInfo.Name + "\n"); | |
Console.ForegroundColor = ConsoleColor.White; | |
} | |
nestingLevel += 1; | |
printFilesInDir(dirInfo); | |
DirectoryInfo[] subDirs = dirInfo.GetDirectories(); | |
if (subDirs.Length != 0) { | |
for (int i = 0; i < subDirs.Length; i++) { | |
traceDirectoryTree(subDirs[i]); | |
} | |
} | |
nestingLevel -= 1; | |
} | |
static void Main(string[] args) { | |
Console.OutputEncoding = Encoding.UTF8; | |
string path; | |
if (args.Length == 0) { | |
path = "."; | |
} | |
else { | |
path = args[0]; | |
} | |
DirectoryInfo dir = new DirectoryInfo( path ); | |
traceDirectoryTree(dir); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment