遍历文件夹

//遍历文件夹
    public void SearchFile(string fileDirectory)
    {
        DirectoryInfo dir = new DirectoryInfo(fileDirectory);
        FileSystemInfo[] f = dir.GetFileSystemInfos();
        foreach (FileSystemInfo i in f)
        {
            //如果是文件夹
            if (i is DirectoryInfo)
            {
                SearchFile(i.FullName);
            }
            else
            {
                FileInfo file = new FileInfo(i.FullName);
                StringBuilder strFile = new StringBuilder();
                strFile.Append("文件名:" + file.Name + "   ");
                strFile.Append("文件路径:" + file.FullName + "  ");
                strFile.Append("文件大小:" + file.Length.ToString() + "<br/>");
                Response.Write(strFile.ToString());
            }
        }
    }

 

posted @ 2014-07-06 00:28  最爱晴天  阅读(377)  评论(0编辑  收藏  举报