Skip to content

Instantly share code, notes, and snippets.

@naepalm
Created August 17, 2016 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naepalm/d99beb806e9bdf124c3a499fc5e223c8 to your computer and use it in GitHub Desktop.
Save naepalm/d99beb806e9bdf124c3a499fc5e223c8 to your computer and use it in GitHub Desktop.
Displays a list of directories and files on a server, for those nasty moments when you don't have access and are looking for something.
@helper RenderFolders(string dirPath, bool displaySubDirs = false)
{
try
{
List<string> dirs = new List<string>(Directory.EnumerateDirectories(dirPath));
<h4>@string.Format("Directory: {0}", dirPath.Substring(dirPath.LastIndexOf("\\") + 1))</h4>
<p>@(string.Format("{0} directories found.", dirs.Count))</p>
<ul>
@foreach (var dir in dirs)
{
<li>
@if (displaySubDirs && Directory.EnumerateDirectories(dir).Any())
{
@RenderFolders(dir, true)
}
else
{
@(string.Format("Directory: {0}", dir.Substring(dir.LastIndexOf("\\") + 1)))
}
@if (Directory.EnumerateFiles(dir).Any())
{
<ul>
@foreach (var file in Directory.EnumerateFiles(dir))
{
<li>@("File: " + file)</li>
}
</ul>
}
</li>
}
</ul>
}
catch (Exception ex)
{
@("Error: " + ex.Message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment