C# 获取指定文件夹下指定类型文件

      ///


        /// 根据条件获取相关后缀的文件  没有子文件的
        ///

        ///
        ///
        ///
        private List getFiles(string path,  string suffix)
        {

            List fileList = new List(); //这个model自己创建

            if (!Directory.Exists(path))//如果路径不存在则创建路径
            {
                Directory.CreateDirectory(path);
            }
            string filename;
            DirectoryInfo dir = new DirectoryInfo(path);
            FileInfo[] file = dir.GetFiles().OrderByDescending(n => n.LastWriteTime).ToArray();
       
            foreach (FileInfo f in file)
            {
                filename = f.FullName;
                if (filename.EndsWith(suffix))//判断文件后缀,并获取指定格式的文件全路径增添至fileList
                {
                    FileModel model = new FileModel();
                    model.FullName = f.FullName;
                    model.MAOPERATIONTIME = DateTime.Now;
                    model.Name = f.Name;
                    fileList.Add(model);
                }
            }
            return fileList;
        }

你可能感兴趣的:(后台,c#,p2p,linq)