.net - Looping file names -


i trying loop through files in folder , list ones contain text in filename. example, while moving new file test.pdf in folder x, if there file named test.pdf in folder new file should renamed test1.pdf , on. in order first trying find count of existing files contain word test in names.

this code have far:

for each foundfile string in my.computer.filesystem.getfiles(varfolderpath, fileio.searchoption.searchtoplevelonly, varfilename & "*")     if foundfile.contains(varfilename)                                                                                      response.write(foundfile & "</br>")     end if next 

the value of variable varfilename being passed test.pdf.

currently, have test.pdf, test1.pdf , test2.pdf in folder, reason, code, instead of listing 3 files, shows me test.pdf in response.

if change for each loop to:

for each filename string in directory.getfiles(varfolderpath, varfilename & "*") 

then still same result of test.pdf. why?

currently have test.pdf, test1.pdf , test2.pdf in folder reason code, instead of listing 3 files, shows me test.pdf file in response.write.

well that's simple. name "test1.pdf" doesn't contain "test.pdf", if view case-insensitively.

maybe should matching extension , non-extension parts separately - checking whether extensions match and first part of filename starts first part of search filename. like:

dim extension = path.getextension(varfilename) dim rest = path.getfilenamewithoutextension(varfilename) if path.getextension(foundfile) = extension andalso _    path.getfilenamewithoutextension(foundfile).startswith(rest)     response.write(foundfile & "</br>") end if 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -