CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2018
    Posts
    6

    Post 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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: How to Limit number of files read

    You already got the answers in the CP Forum
    Victor Nijegorodov

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
  •  





Click Here to Expand Forum to Full Width

Featured