国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

C#實(shí)現(xiàn)目標(biāo)路徑下文件遞歸的類

2024-07-21 02:27:40
字體:
供稿:網(wǎng)友

using system;
using system.io;
using system.collections;

namespace dsclub
{
    /**//// <summary>
    /// dirlist 的摘要說明。
    /// </summary>
    public class dirlist
    {
        private string strinitfilepath;
        private bool bfatchall;

        // 構(gòu)造函數(shù)
        public dirlist()
        {
            bfatchall = false;
            strinitfilepath = "c://";
        }
        public dirlist(string strfilepath)
        {
            bfatchall = false;
            strinitfilepath = strfilepath;
        }

        // 是否遞歸出所有的文件
        public bool recursionfiles
        {
            get
            {
                return bfatchall;
            }
            set
            {
                bfatchall = value;
            }
        }

        // 取得文件的函數(shù)
        public arraylist getfiles()
        {
            return getfiles(strinitfilepath, bfatchall);
        }

        public static arraylist getfiles(string strpath, bool resultsall)
        {
            arraylist al  = new arraylist();
            // 判斷路徑是否存在
            if(!directory.exists(strpath))
            {
                throw(new applicationexception("訪問的路徑" + strpath + "不存在,或者它不是個文件夾。"));
            }

            string[] temp =  directory.getfiles(strpath);
            foreach(string afile in temp)
            {
                al.add(afile);
            }

            // 如果此目錄下不存在文件,則把文件夾路徑返回,并用///作標(biāo)識
            if(temp.length == 0)
            {
                al.add("http:///" + strpath);
            }

            if(resultsall)
            {
                temp = directory.getdirectories(strpath);
                foreach(string adir in temp)
                {
                    al.addrange(getfiles(adir, resultsall));
                }
            }
           
            return al;
        }

    }
}

其中關(guān)于應(yīng)該有系統(tǒng)文件的檢查,還有用戶不可訪問系統(tǒng)文件夾的判斷,但是這個項(xiàng)目中用不上,又不想用try塊兒影響效率。

還是遞歸的思想!



收集最實(shí)用的網(wǎng)頁特效代碼!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 汉寿县| 谷城县| 诏安县| 柘城县| 孟连| 隆子县| 北川| 惠来县| 长兴县| 三台县| 清水河县| 巴中市| 濉溪县| 台前县| 清镇市| 台江县| 宁强县| 莱芜市| 申扎县| 东阿县| 霍城县| 恩平市| 苍南县| 平凉市| 兴山县| 盐山县| 龙州县| 根河市| 吴川市| 鹿邑县| 闽清县| 荣成市| 闵行区| 兖州市| 永登县| 鄂州市| 汝城县| 清涧县| 象山县| 龙海市| 抚州市|