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

首頁 > 編程 > .NET > 正文

asp.net遍歷目錄文件夾和子目錄所有文件

2024-07-10 13:22:26
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;

namespace copefile
{
    class Program
    {
        static void Main(string[] args)
        {
            string testDir = "e:/xunlei/";
            listFiles(testDir,0);
            Console.ReadKey();
        }

        public static void listFiles(string dir, int level)
        {
           //阿會楠練習作品,程序多有參考
            try
            {
                //獲取文件列表
                string[] files = Directory.GetFiles(dir);

                String preStr = "";
                for (int i = 0; i < level; i++)
                {
                    preStr += "    ";
                }

                foreach (string f in files)
                {
                    if (f.LastIndexOf("http://") == -1)
                    {
                        Console.WriteLine(preStr + f.Substring(f.LastIndexOf("http://m.survivalescaperooms.com/") + 1));
                    }
                    else
                    {
                        Console.WriteLine(preStr + f.Substring(f.LastIndexOf("http://") + 1));
                    }

                }

                //獲取目錄列表
                string[] dirs = Directory.GetDirectories(dir);
                foreach (string d in dirs)
                {
                    if (d.LastIndexOf("http://") == -1)
                    {
                        Console.WriteLine(preStr + d.Substring(d.LastIndexOf("http://m.survivalescaperooms.com/") + 1));
                    }
                    else
                    {
                        Console.WriteLine(preStr + d.Substring(d.LastIndexOf("http://") + 1));
                    }
                    if (Directory.Exists(d))
                    {
                        listFiles(d, level + 1);
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 佳木斯市| 白山市| 固镇县| 永宁县| 柞水县| 甘谷县| 阜城县| 梅河口市| 太湖县| 兴山县| 德格县| 资源县| 新密市| 方正县| 江陵县| 沧州市| 兴仁县| 望奎县| 弥渡县| 浠水县| 屏东市| 进贤县| 武陟县| 康马县| 特克斯县| 辛集市| 晋城| 杭州市| 江门市| 临武县| 荣成市| 清水河县| 仙居县| 通州区| 蓝田县| 赤峰市| 建平县| 九江县| 襄汾县| 萨迦县| 长宁县|