c# - to get the number of files recursively -


i'm trying count number of *.tmp files in computer. when click on button labelbox should start increasing count number each search of .tmp file. below coding not seems working.

any appreciated. when click on button number of tmp files; lable box should start showing increase in count 1,2,,,,,56,,89,,,etc rather showing total number of files.

namespace finalclean {  public partial class finalclean : form {      public finalclean() {          initializecomponent();     }      int count = 0;       private void button1_click(object sender, eventargs e) {         string path = environment.expandenvironmentvariables(@"c:\windows");         try {            foreach (string dirpath in directory.getdirectories(path)) {                 foreach (string filepath in directory.getfiles(dirpath)) {                     string filename = path.getfilename(filepath);                     if (filename.equals("*.tmp")) {                        count++;                    }                }            }        }          catch (system.exception excpt) {              //console.writeline(excpt.message);          }        textbox1.text = (count.tostring());     }    }  } 

you use:

var count = directory.enumeratefiles(@"c:\windows\", "*.tmp",                        searchoption.alldirectories).count(); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -