享受自由与创造的乐趣!

I LOVE THIS GAME

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::


 

        int fileNum = 0;
        
/// <summary>
        
/// 获取某目录下的所有文件(包括子目录下文件)的数量
        
/// </summary>
        
/// <param name="srcPath"></param>
        
/// <returns></returns>

        public int GetFileNum(string srcPath)
        
{
            
try
            
{

                
// 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                
// 遍历所有的文件和目录
                foreach(string file in fileList)
                
{
                    
// 先当作目录处理如果存在这个目录就重新调用GetFileNum(string srcPath)
                    if(System.IO.Directory.Exists(file))
                        GetFileNum(file);
                    
else
                        fileNum
++;
                }

                
            }

            
catch (Exception e)
            
{
                MessageBox.Show (e.ToString());
            }

            
return fileNum;
        }

posted on 2005-08-23 12:34  helloworld84  阅读(12524)  评论(3)    收藏  举报