C # Get all the files in the directory or specify file type files (including all subfolders)

Source: Internet
Author: User
A method. Call directly
Returns a list of file details that can be obtained by obtaining a lot of file information. You can try.
Parameter path-folder extname-extensions can be multiple for example. mp3.wma.rm

public class FileGet
... {
Private list<fileinfo> LST = new list<fileinfo> ();
Public list<fileinfo> GetFile (string path, String extname)
... {
Getdir (path, extname);
return LST;
}
private void Getdir (string path, String extname)
... {
Try
... {
string[] dir = directory.getdirectories (path); Folder List
DirectoryInfo fdir = new DirectoryInfo (path);
fileinfo[] File = Fdir. GetFiles ();
fileinfo[] File = directory.getfiles (path); File list
if (file. Length!= 0 | | Dir. Length!= 0)//The current directory file or folder is not empty
... {
foreach (FileInfo f in file)//Show All files in current directory
... {
if (Extname.tolower (). IndexOf (F.extension.tolower ()) >= 0)
... {
Lst. ADD (f);
}
}
foreach (String d in dir)
... {
Getdir (d, extname);//recursion
}
}
}
Catch... { };
}
}
Related Article

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.