zoukankan      html  css  js  c++  java
  • 得到目录下的所有文件


     

     //得到目录下的所有文件夹  dirpath是目录路径  listpaths是用于保存文件全路径

    public static void Get_All_Filepath_In_Directory(string dirpath, List<string> listpaths)
            {
                List<string> filePaths = listpaths;   //存放文件的路径
                try
                {
                    if (Is_Directory(dirpath))   //判断是否存在目录
                    {

                        filePaths.AddRange(Directory.GetFiles(dirpath).ToList());   //Directory.GetFiles(dirpath)得到目录下所有的文件
                        List<string> listDir = Directory.GetDirectories(dirpath).ToList();  //Directory.GetDirectories(dirpath)  得到目录下的所有子目录
                            foreach (var item in listDir)
                            Get_All_Filepath_In_Directory(item, filePaths);  //递归调用
                    }

                }
                catch (Exception ex)
                {
                      //code...
                }
                finally
                {
                     //code...
                }
            }

     public static bool Is_Directory(string path)  //判断目录是否存在
            {
                bool flag = false;
                try
                {
                    if (!string.IsNullOrWhiteSpace(path))  //判断目录是否为null或者是空
                    {
                        if (Directory.Exists(path))   //存在返回TRUE
                        {
                            return true;
                        }
                    }
                    return flag;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
  • 相关阅读:
    vue组件传值
    mui父子页面蒙版
    mui页面传值
    mui跳转页面短暂白屏
    Sql 向数据库中添加一行数据
    redis启动报错 no config file specified, using the default config.
    C# 合并表达式树
    .net从集合中取出下拉框类型值数据
    jquery从数组中取出满足要求的元素
    RabbitMQ Topic交换机代码实现
  • 原文地址:https://www.cnblogs.com/zhangyuanbo12358/p/3830387.html
Copyright © 2011-2022 走看看