AI智能
改变未来

C#学习.统计文件个数

        static long FileOrDirCount(string path)
        {
            long count = 0;
            //统计File个数
            try
            {
                var Files = Directory.GetFiles(path);
                count += Files.Length;
                //统计directory个数
                var dirs = Directory.GetDirectories(path);
                foreach (var dir in dirs)
                {
                    count += FileOrDirCount(dir);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);                
            }
                    
            return count;
        }
        static void Main(string[] args)
        {
           Console.WriteLine(\”{0}\”, FileOrDirCount(\”E:\\\\\”));
           Console.ReadLine();
        }

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » C#学习.统计文件个数