c# - Get files in directory with multiple search patterns -


i have method gets files in specified directory extension txt. besides files, want files extensions ppt, docx etc. how achieve that?

this current code:

private void button2_click(object sender, eventargs e){   listview1.items.clear();   if (textbox1.text != ""){     list<string> files = new list<string>();     files = directory.getfiles(textbox1.text, "*.txt,*.ppt").tolist();     progressbar1.maximum = files.count;     progressbar1.value = 0;     listviewitem it;     foreach (var file in files){       = new listviewitem(file.tostring());       it.subitems.add(system.io.path.getfilename(file.tostring()));       it.subitems.add(system.io.path.getextension(file.tostring()));       listview1.items.add(it);       progressbar1.increment(1);     }   } else     messagebox.show("select directory first"); } 

your question not clear understand want files different extension specified path. can't using directory.getfiles("c://etc.", "*.txt") because works on single search pattern. can use this,

string[] extensions = {"*.txt", "*.doc", "*.ppt"}; foreach(var ext in extensions) {     getfiles(ext); } private void getfiles(string ext) {     list<string> files = new list<string>();     files = directory.getfiles("c:/something", ext).tolist();     // want these files. } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -