search - Searching all jpg's from all drives in a computer vb.net -


i want list jpg files drives in computer there full path. tried following code list few random files, wont search files. got here: searching drive vb.net

public sub dirsearch(byval sdir string)     dim fl string      try         each dir string in directory.getdirectories(sdir)             each fl in directory.getfiles(dir, "*.jpg")                 listbox1.items.add(fl)              next              dirsearch(dir)         next       catch ex exception         debug.writeline(ex.message)     end try end sub 

'form1 load event

 private sub form1_load(sender object, e eventargs) handles mybase.load      dirsearch("c:\")     dirsearch("d:\")     dirsearch("e:\")     dirsearch("f:\")     dirsearch("g:\")     dirsearch("h:\")     dirsearch("i:\")     dirsearch("j:\")     dirsearch("k:\")     'dirsearch("so on.....")     savetxtfile()     end sub 

save searched result text file in system drive

sub savetxtfile()     dim systemdrv string = mid(environment.getfolderpath(environment.specialfolder.system), 1, 3)       textbox1.text = listbox1.items.count     dim w io.streamwriter     dim r io.streamreader      dim integer     w = new io.streamwriter(systemdrv + "temp\test.txt")     = 0 listbox1.items.count - 1         w.writeline(listbox1.items.item(i))     next     w.close() end sub 

you're ignoring exception...

debug.writeline(ex.message) 

use instead (so can't miss debugging)...

messagebox.show(ex.message) 

knowing what's happening folder access error, need handle accordingly.

for each dir string in directory.getdirectories(sdir)     try         each fl in directory.getfiles(dir, "*.jpg")             lstbxtest.items.add(fl)         next     catch ex exception         continue     end try next 

effectively, continue if error, because don't care in case.

you might want add exceptions in there (if dir = "whatever" continue for) you're not trying go through every single system folder in operating system.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -