How to Limit number of files read
I am using this code to list all the directories and files within these directories.
var dir = @"C:\temp\TestDir";
int option = 1;
switch(option)
{
case 1:
{
PrintDirectoryTree(dir, 2, new string[] { "folder3" });
break;
}
public static void PrintDirectoryTree(string directory, int lvl, string[] excludedFolders = null, string lvlSeperator = "")
{
excludedFolders = excludedFolders ?? new string[0];
foreach (string f in Directory.GetFiles(directory))
{
Console.WriteLine(lvlSeperator + Path.GetFileName(f));
}
foreach (string d in Directory.GetDirectories(directory))
{
Console.WriteLine(lvlSeperator + "-" + Path.GetFileName(d));
if (lvl > 0 && Array.IndexOf(excludedFolders, Path.GetFileName(d)) < 0)
{
PrintDirectoryTree(d, lvl - 1, excludedFolders, lvlSeperator + " ");
}
}
}
Some subdirectories may have more than 100 files.
How to list only first 15 files from each subdirectory?
Re: How to Limit number of files read
You already got the answers in the CP Forum