• C#递归实现文件遍历


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                 string rootpath = "C:\Users\Eric\Desktop\jm20";
                 sendFiles(rootpath);
                 Console.ReadKey();
               
            }
            static  void sendFiles(string rootpath) //递归实现文件的遍历
            {
                string[] subPaths = System.IO.Directory.GetDirectories(rootpath);//得到所有子目录
    
                foreach (string path in subPaths)
                {
                    sendFiles(path);//对每一个子目录做与根目录相同的操作:即找到子目录并将当前目录的文件名存入List
                }
                string[] files = System.IO.Directory.GetFiles(rootpath);//得到目录下的所有文件
                int size = files.Length;
                foreach (string file in files)
                {
                    string filenew = file.Remove(0, "C:\Users\Eric\Desktop\jm20".Length + 1);  //所有文件的相对路径
                    Console.WriteLine("FileName:{0}", filenew);               
                }
            }
        }
    }
  • 相关阅读:
    08简单推导:手机尾号评分
    07简单推导:生日蜡烛
    06普通推导
    05简单推导:猴子吃桃
    简单推导
    03map用法
    List题目
    02List的使用
    01基础知识
    HDU
  • 原文地址:https://www.cnblogs.com/zxwAAA/p/3367220.html
Copyright © 2020-2023  润新知