Monday, 13 February 2017

Get file count from directory using C#



public static void Main()
        {
            var file =new  DirectoryInfo(@"E:\Your Folder path");
            var fileinfo = file.GetFiles("*", SearchOption.AllDirectories);
            foreach (var item in fileinfo)
            {
                Console.WriteLine("File Name => " + item.FullName);
            }
            Console.WriteLine("File total count => " + fileinfo.Length);
            Console.ReadLine();
        }

Note=> you will gave your Directory info path and it will find all find SubDirectory or Directory

//OR we can write in one line like that below .


int fileCount = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Length;


but it will gave you how many file are  inside your folder path.

No comments:

Post a Comment