zoukankan      html  css  js  c++  java
  • 递归遍历文件及子文件夹下的文件(该代码是复制过来修改过的,如果有侵作者权的话,请作者联系我,立即删除)

    调用: ListFiles(new DirectoryInfo(source));  
    
    /// <summary>
            /// //递归遍历所有文件包括子文件夹下的文件 并对word excel pdf文件进行复制到目标路径
            /// </summary>
            /// <param name="info"></param>
            private void ListFiles(FileSystemInfo info)
            {
                if (!info.Exists) { return; }
    
                DirectoryInfo dir = info as DirectoryInfo;
                //不是目录 
                if (dir == null) { return; }
    
    
                FileSystemInfo[] files = dir.GetFileSystemInfos();
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i] as FileInfo;
                    //是文件 
    
                    if (file != null)
                    {
                        string[] arr = file.Name.Split(new char[] { '.' });
    
                        arr[arr.Length - 1] = arr[arr.Length - 1].ToLower();
    
                        if (arr[arr.Length - 1] == "doc" || arr[arr.Length - 1] == "docx")
                        {
    
                        
    
                            #region 每扫描到一个word文件 存储到lst里面去
    
                            FilesModelRepostory fileModel = new FilesModelRepostory();
    
                            fileModel.ID = Guid.NewGuid().ToString("N");
                            fileModel.FileName = file.Name;
                            fileModel.FileType =FileType.Word;
                            
                            AddJob(fileModel);
    
    
    
    
    
                            #endregion
    
    
                            count++;
                        }
                        if (arr[arr.Length - 1] == "xls" || arr[arr.Length - 1] == "xlsx")
                        {
                           
    
                            #region 每扫描到一个Excel文件 存储到lst里面去
    
                            FilesModelRepostory fileModel = new FilesModelRepostory();
                            fileModel.ID = Guid.NewGuid().ToString("N");
                            fileModel.FileName = file.Name;
                            fileModel.FileType = FileType.Excel;
    
                            AddJob(fileModel);
    
                            #endregion
    
                            count++;
                        }
                        if (arr[arr.Length - 1] == "pdf")
                        {
                        
    
                            #region 每扫描到一个pdf文件 存储到lst里面去
    
                            FilesModelRepostory fileModel = new FilesModelRepostory();
                            fileModel.ID = Guid.NewGuid().ToString("N");
                            fileModel.FileName = file.Name;
                            fileModel.FileType =FileType.Pdf;
    
                            AddJob(fileModel);
    
    
    
    
                            #endregion
    
                            count++;
                        }
                    }
                    //对于子目录,进行递归调用 
                    else
                    {
                        ListFiles(files[i]);
                    }
                }
    
            }
    

      

  • 相关阅读:
    redux VS mobx (装饰器配合使用)
    react-native 中使用 mobx
    使用 react-native-tab-navigator 创建 TabBar 组件
    react-native ListView 封装 实现 下拉刷新/上拉加载更多
    react-native 路由 react-native-router-flux
    react-native fetch 请求封装
    react-native flex 布局 详解
    react-native AsyncStorage 数据持久化方案
    react-native 自定义 下拉刷新 / 上拉加载更多 组件
    用 Core Animation 实现图片的碎片化
  • 原文地址:https://www.cnblogs.com/zjw520/p/3014670.html
Copyright © 2011-2022 走看看