vb.net - Populate Listbox with directory contents but only accept certain extensions -
so, drag in folder onto form, , listbox populates paths of files inside. i've managed make listbox accept .mp3 paths, how can add more accepted extensions?
private sub form1_dragdrop(sender system.object, e system.windows.forms.drageventargs) handles me.dragdrop dim files() string = e.data.getdata(dataformats.filedrop) each path in files if directory.exists(path) 'add contents of folder listbox1 listbox1.items.addrange(io.directory.getfiles(path, "*.mp3*")) as can see in last line above, paths in folder having .mp3 extension accepted. how add more accepted extensions, .avi, .mp4 etc?
i've tried listbox1.items.addrange(io.directory.getfiles(path, "*.mp3*" + "*.mp4*"))
i've tried listbox1.items.addrange(io.directory.getfiles(path, "*.mp3*" , "*.mp4*"))
no luck !
you should create loop, test extension, , add or not...
something like;
dim allowedextension string = "mp3 mp4" each file string in io.directory.getfiles("c:\", "*.*") if allowedextension.contains(io.path.getextension(file).tolower) listbox1.items.add(file) end if next or more dirty;
io.directory.getfiles(path, "*.mp*") or twice;
add
listbox1.items.addrange(io.directory.getfiles(path, "*.mp3*")) and
listbox1.items.addrange(io.directory.getfiles(path, "*.mp4*"))
Comments
Post a Comment