Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get the All directories/Files Info in c#

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 229
    Comment on it

    HI Friends,

    Today i will specify you how we can access directories from a specific path in c# . Below code justify the functionality :-

    try
                {
                    DirectoryInfo directoryinfo = new DirectoryInfo(@"D:\Test");
    
                    //Get all directories from specified path
                    DirectoryInfo[] data = directoryinfo.GetDirectories();
    
                    //Pick up all directories using for each loop
                    foreach (DirectoryInfo item in data)
                    {
                        FileInfo[] files = item.GetFiles();
    
                        //Get all files
                        foreach (var file in files)
                        {
                            Console.WriteLine(file.Name);
                        }
                        Console.WriteLine("Directory Name :" + item.Name + "\tTotal File :" + files.Count());
                    }
                    Console.WriteLine(data.Count());
                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    //Log exception
                }

    Thanks 
    Happy Coding!!

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: