C# – Display Folder Contents with Console Application – Directory Info Usage

With the current console application we display the contents of a given folder.

It is a little useless by itself, but the code has one good advantage – it shows perfect application of DirectoryInfo and some properties as .FullName & .GetDirectories.

So, in general, if you want to see the contents of any folder, simply change the line “C:\\DOWNLOADS” at the bottom lines to any other tree you may like to explore. In order to escape the “\” symbol in C#, you should double it. Thus instead of “C:\Windows”, you should write “C:\\Windows”.

Furthermore, every depth level of the given directory starts with a little more on the right.

Here is the code:

Some of the code of the current article is part of the free Bulgarian C# programming book.