.net - Get All Directories -
i followed tutorial create file explorer in visual basic 2010.
this line of code dim info new directoryinfo("../..")
gets directory ever programme started.
i wondering how forcefulness programme list directories on c drive changing previous line of code.
this code have:
private sub populatetreeview() dim rootnode treenode dim info new directoryinfo("../..") if info.exists rootnode = new treenode(info.name) rootnode.tag = info getdirectories(info.getdirectories(), rootnode) treeview1.nodes.add(rootnode) end if end sub private sub getdirectories(byval subdirs() directoryinfo, _ byval nodetoaddto treenode) dim anode treenode dim subsubdirs() directoryinfo dim subdir directoryinfo each subdir in subdirs anode = new treenode(subdir.name, 0, 0) anode.tag = subdir anode.imagekey = "folder" subsubdirs = subdir.getdirectories() if subsubdirs.length <> 0 getdirectories(subsubdirs, anode) end if nodetoaddto.nodes.add(anode) next subdir end sub public sub new() initializecomponent() populatetreeview() end sub 'new private sub treeview1_nodemouseclick(byval sender object, _ byval e treenodemouseclickeventargs) _ handles treeview1.nodemouseclick dim newselected treenode = e.node listview1.items.clear() dim nodedirinfo directoryinfo = _ ctype(newselected.tag, directoryinfo) dim subitems() listviewitem.listviewsubitem dim item listviewitem = nil dim dir directoryinfo each dir in nodedirinfo.getdirectories() item = new listviewitem(dir.name, 0) subitems = new listviewitem.listviewsubitem() _ {new listviewitem.listviewsubitem(item, "directory"), _ new listviewitem.listviewsubitem(item, _ dir.lastaccesstime.toshortdatestring())} item.subitems.addrange(subitems) listview1.items.add(item) next dir dim file fileinfo each file in nodedirinfo.getfiles() item = new listviewitem(file.name, 1) subitems = new listviewitem.listviewsubitem() _ {new listviewitem.listviewsubitem(item, "file"), _ new listviewitem.listviewsubitem(item, _ file.lastaccesstime.toshortdatestring())} item.subitems.addrange(subitems) listview1.items.add(item) next file listview1.autoresizecolumns(columnheaderautoresizestyle.headersize) end sub
you need seek grab beaus there files have no right access. allow code jump on utilize catch.
otherwise errors cant access recycle files , on.
so when start each set seek there."like code below"
change dim info new directoryinfo("../..") dim info new directoryinfo("c:\")
private sub getdirectories(byval subdirs() directoryinfo, _ byval nodetoaddto treenode) dim anode treenode dim subsubdirs() directoryinfo dim subdir directoryinfo each subdir in subdirs seek anode = new treenode(subdir.name, 0, 0) anode.tag = subdir anode.imagekey = "folder" subsubdirs = subdir.getdirectories() if subsubdirs.length <> 0 getdirectories(subsubdirs, anode) end if nodetoaddto.nodes.add(anode) grab ex exception end seek next subdir end sub
.net vb.net vb.net-2010
No comments:
Post a Comment