亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時(shí)間:2008年05月01日 09:40:17   作者:  
用asp.net實(shí)現(xiàn)遍歷目錄文件和子目錄的代碼
復(fù)制代碼 代碼如下:

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)
        {
           //阿會(huì)楠練習(xí)作品,程序多有參考
            try
            {
                //獲取文件列表
                string[] files = Directory.GetFiles(dir);

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

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

                }

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

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

相關(guān)文章

最新評(píng)論