vb.net - List all folders that are in any 3rd subdirectory from current -
i need make array list, displaying folders in 3rd subfolder current one.
folder1/sub1folder/sub2folder/sub3folder
it has recursive. need array of strings contains strings above. know how recursively folders, not know how limit search 3rd subfolder.
thanks!
here's stab @ it. tested , works me:
dim resultlist list(of string) = directorysearch(basedirectorypath, 0) function directorysearch(directorypath string, level integer) list(of string) level += 1 dim directories string() = io.directory.getdirectories(directorypath) dim resultlist new list(of string) if level = 3 each subdirectorypath in directories dim result string = getfinalresult(subdirectorypath) resultlist.add(result) next else each subdirectorypath in directories dim partialresultlist list(of string) = directorysearch(subdirectorypath, level) resultlist.addrange(partialresultlist) next end if return resultlist end function private function getfinalresult(directorypath string) string dim directoryinfo new io.directoryinfo(directorypath) return string.format("{0}/{1}/{2}/{3}", directoryinfo.parent.parent.parent.name, directoryinfo.parent.parent.name, directoryinfo.parent.name, directoryinfo.name) end function
Comments
Post a Comment