c# - Further Filter Files Returned from Looping Through a Directory -


i have pretty little piece of code loop through networked drive , return file name , extension of files. have output set display in listbox. current conundrum pulls in temp files "~filename.ext" , throwing off count. how go directing ignore temp files "~filename.ext".

string[] filepaths = directory.getfiles(@"\\server\directory\folder\folder\", "*.xlsm",                      searchoption.alldirectories);         statuscodelb.items.clear();         foreach (string file in filepaths)         {             statuscodelb.items.add(path.getfilename(file));          }         statuslabel.text = statuscodelb.items.count.tostring(); 

you can use if statement in loop check whether file name starts "~" this:

//... foreach (string file in filepaths) {     string filename = path.getfilename(file);      if(filename.startswith("~"))         continue; //skip      statuscodelb.items.add(filename); } //... 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -