• C# 获取指定目录下所有文件信息、移动目录、拷贝目录


    /// <summary>
            /// 返回指定目录下的所有文件信息
            /// </summary>
            /// <param name="strDirectory"></param>
            /// <returns></returns>
            public List<FileInfo> GetAllFilesInDirectory(string strDirectory)
            {
                List<FileInfo> listFiles = new List<FileInfo>(); //保存所有的文件信息  
                DirectoryInfo directory = new DirectoryInfo(strDirectory);
                DirectoryInfo[] directoryArray = directory.GetDirectories();
                FileInfo[] fileInfoArray = directory.GetFiles();
                if (fileInfoArray.Length > 0) listFiles.AddRange(fileInfoArray);
                foreach (DirectoryInfo _directoryInfo in directoryArray)
                {
                    DirectoryInfo directoryA = new DirectoryInfo(_directoryInfo.FullName);
                    DirectoryInfo[] directoryArrayA = directoryA.GetDirectories();
                    FileInfo[] fileInfoArrayA = directoryA.GetFiles();
                    if (fileInfoArrayA.Length > 0) listFiles.AddRange(fileInfoArrayA);
                    GetAllFilesInDirectory(_directoryInfo.FullName);//递归遍历  
                }
                return listFiles;
            }
    
    /// <summary>
            /// 返回指定目录下的所有文件信息
            /// </summary>
            /// <param name="strDirectory"></param>
            /// <returns></returns>
            public List<FileInfo> GetAllFilesInDirectory(string strDirectory)
            {
                List<FileInfo> listFiles = new List<FileInfo>(); //保存所有的文件信息  
                DirectoryInfo directory = new DirectoryInfo(strDirectory);
                DirectoryInfo[] directoryArray = directory.GetDirectories();
                FileInfo[] fileInfoArray = directory.GetFiles();
                if (fileInfoArray.Length > 0) listFiles.AddRange(fileInfoArray);
                foreach (DirectoryInfo _directoryInfo in directoryArray)
                {
                    DirectoryInfo directoryA = new DirectoryInfo(_directoryInfo.FullName);
                    DirectoryInfo[] directoryArrayA = directoryA.GetDirectories();
                    FileInfo[] fileInfoArrayA = directoryA.GetFiles();
                    if (fileInfoArrayA.Length > 0) listFiles.AddRange(fileInfoArrayA);
                    GetAllFilesInDirectory(_directoryInfo.FullName);//递归遍历  
                }
                return listFiles;
            }
    
    /// <summary>
            /// 返回指定目录下的所有文件信息
            /// </summary>
            /// <param name="strDirectory"></param>
            /// <returns></returns>
            public List<FileInfo> GetAllFilesInDirectory(string strDirectory)
            {
                List<FileInfo> listFiles = new List<FileInfo>(); //保存所有的文件信息  
                DirectoryInfo directory = new DirectoryInfo(strDirectory);
                DirectoryInfo[] directoryArray = directory.GetDirectories();
                FileInfo[] fileInfoArray = directory.GetFiles();
                if (fileInfoArray.Length > 0) listFiles.AddRange(fileInfoArray);
                foreach (DirectoryInfo _directoryInfo in directoryArray)
                {
                    DirectoryInfo directoryA = new DirectoryInfo(_directoryInfo.FullName);
                    DirectoryInfo[] directoryArrayA = directoryA.GetDirectories();
                    FileInfo[] fileInfoArrayA = directoryA.GetFiles();
                    if (fileInfoArrayA.Length > 0) listFiles.AddRange(fileInfoArrayA);
                    GetAllFilesInDirectory(_directoryInfo.FullName);//递归遍历  
                }
                return listFiles;
            }
    
  • 相关阅读:
    26个Jquery使用小技巧
    jQuery之浮动窗口
    Visual Studio 2010 TFS指南
    Python
    HTML5小菜
    记一次重构经历【转载】
    Python学习笔记
    Spring.Net+NHibenate+Asp.Net mvc +ExtJs 系列
    搜索分词实现
    UML概要
  • 原文地址:https://www.cnblogs.com/shuang121/p/3171746.html
Copyright © 2020-2023  润新知