C #. NET get all specified types of files in the specified folder

Source: Internet
Author: User

Code /// <summary> /// obtain the names of all objects in the specified folder /// </summary> /// <param name = "folderName"> specify the folder name, absolute path </param> /// <param name = "fileFilter"> filter file types based on the file suffix, for example :*,*. txt ,*. xls </param> /// <param name = "isContainSubFolder"> include subfolders </param> /// <returns> ArrayList array, name of all required file paths </returns> public static ArrayList GetAllFilesByFolder (string folderName, string fileFilter, bool isContainSubFolder) {ArrayList resArray = new ArrayList (); string [] files = Directory. getFiles (folderName, fileFilter); for (int I = 0; I <files. length; I ++) {resArray. add (files [I]);} if (isContainSubFolder) {string [] folders = Directory. getDirectories (folderName); for (int j = 0; j <folders. length; j ++) {// traverse all folders ArrayList temp = GetAllFilesByFolder (folders [j], fileFilter, isContainSubFolder); resArray. addRange (temp) ;}}return resArray ;}/// <summary >/// obtain the names of all objects in the specified folder, do not filter the file type /// </summary> /// <param name = "folderName"> specify the folder name, absolute path </param> /// <param name = "isContainSubFolder"> include subfolders </param> /// <returns> ArrayList array, name of all required file paths </returns> public static ArrayList GetAllFilesByFolder (string folderName, bool isContainSubFolder) {return GetAllFilesByFolder (folderName, "*", isContainSubFolder );}

 

 

Programmers are interested in. NET software development, Matlab hybrid programming, and network technology.

Welcome to my Cnblog blog: http://www.cnblogs.com/asxinyu/

Welcome to our discussion. QQ: 1287263703

E-mail: asxinyu@qq.com, asxinyu@126.com

Tag: Matlab, Matlab development, Matlab hybrid programming, C #. NET Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.