asp.net - Getting name(s) of FOLDER containing a specific SUBSTRING from the C:Temp directory in C# -
guys title says have names of folders having particular (user indicated) sub string.
i have text box user input wanted sub string. , using codes below achieve goal.
string name = txtnamesubstring.text; string[] allfiles = system.io.directory.getfiles("c:\\temp");//change path yours foreach (string file in allfiles) { if (file.contains(name)) { cblfolderselect.items.add(allfiles); // messagebox.show("match found : " + file); } else { messagebox.show("no files found"); } }
it not work. when trigger it,only message box appears. ?
you can use appropriate api let framework filter directories.
var pattern = "*" + txtnamesubstring.text + "*"; var directories = system.io.directory.getdirectories("c:\\temp", pattern);