How to get multiple files with different suffixes during disk traversal

Source: Internet
Author: User

This is to do a picture to browse the time to think of the problem, think in the picture when there are many different formats of the file needs to be opened, so you have to let the program support this function,

If we just open a type of picture, we might write it like this.

   New ArrayList (); // Store Pictures  string [] files; // folders that need to be opened files = Directory. GetFiles (Path,"*jpg"foreachstring in files)                {                    new  FileInfo (item);                    List. ADD (info);                } return list;

When a variety of times we can put him into a loop to traverse, on the code

  PublicArrayList getimages () {string[] ext = {"*png","*jpg","*bmp"};//the picture format to openArrayList list =NewArrayList ();//Store Pictures            string[] files;  for(inti =0; I <3; i++) {Files=Directory.                GetFiles (Path,ext[i]); foreach(stringIteminchfiles) {FileInfo Info=NewFileInfo (item); List.                ADD (info); }            }                      returnlist; }

How to get multiple files with different suffixes during disk traversal

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.