|
-
January 9th, 2024, 08:28 PM
#1
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?
Last edited by picasso101; January 9th, 2024 at 08:31 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|