473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

VB.NET 05, List Folder, SubFolders, and Sub SubFolders

5
Hey All,

My problem appears to be pretty simple. I need a way of listing all the folders that exist in a certain directory. By all the folders, I mean ALL the folders; any file folder that exists underneath a certain directory needs to be returned, no matter how deep it lies. So, for example,


2 folders in drive X:, one called 'Names' the other called 'Addresses'

'Names' contains 3 different folders, each of which has 2 subfolders of its own

'Addresses' contains 2 different folders, which have no subfolders.


I'm searching for a way to return all the folder paths to a single array. Is there a simple method that accomplishes this? I've been playing around with 'System.IO.Directory.GetDirectories', but this allows me to only drill down one layer, so to speak.

This seems to me like it would be a pretty common task, so I'm curious as to why I can't seem to find a solution on the net (perhaps my googling skills are sub par) Any help would be fantastic.

Running Visual Studio 2005, on XP Pro, .NET Framework 2.0

Thanks Guys/Gals.
May 13 '08 #1
2 12662
The most efficient way would be to use recursivity:
Expand|Select|Wrap|Line Numbers
  1.     Private Function getAllFolders(ByVal directory As String) As String()
  2.         'Create object
  3.         Dim fi As New IO.DirectoryInfo(directory)
  4.         'Array to store paths
  5.         Dim path() As String = {}
  6.         'Loop through subfolders
  7.         For Each subfolder As IO.DirectoryInfo In fi.GetDirectories()
  8.             'Add this folders name
  9.             Array.Resize(path, path.Length + 1)
  10.             path(path.Length - 1) = subfolder.FullName
  11.             'Recall function with each subdirectory
  12.             For Each s As String In getAllFolders(subfolder.FullName)
  13.                 Array.Resize(path, path.Length + 1)
  14.                 path(path.Length - 1) = s
  15.             Next
  16.         Next
  17.         Return path
  18.     End Function
  19.  
May 16 '08 #2
In regard to my last post, perhaps not the most efficient, but certainly the simplest. This may get slow if you're trying to use it on large directories like C:, but for the most part it should be OK.
May 16 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Rosa | last post by:
Hi, I'm trying to clear the TIF on Windows XP programmatically with the below code. This code works fine on any folder but the TIF. For some reason the atEnd() statements always defaults to true...
9
by: Tom | last post by:
How do you programatically get a list of subfolders in a folder? Thanks! Tom
1
by: Tarren | last post by:
Hi: What would be a quick way to iterate through a folder and all of its subfolders, not just its immediate folders? Is there a way to use the GetDirectories method and have it cascade through...
9
by: Bill Nguyen | last post by:
I need a VB routine to loop thru a select top folder to find all subfolders and list all subfolders/files under each of these subfolders. Any help is greatly appreciated. Bill
5
by: Robertico | last post by:
Is it possible to upload a complete folder including the subfolders using PHP ? Regards, Robertico
3
by: TyBreaker | last post by:
I have a vbscript which returns the folder size of any folder instantly by referring to Folder.Size. I don't need any iteration or recursion through the subfolders, adding together individual file...
1
by: shank | last post by:
I borrowed the below code from http://www.brainjar.com/asp/dirlist/ and cannot get it to read my folder files. I don't get any errors or any output to screen. I have the below folder permissions...
0
by: Chuck Anderson | last post by:
I'm trying to come with a good organization plan for the Apache, Php, MySQL development software on my home PC and am wondering what sort of folder structure others may have come up with that seems...
0
by: deve8ore | last post by:
Hi.... I'm getting closer to understanding the wildcard function in VBA, however we have a vendor that will supply us many files, and unfortunately will place them in different folders with no...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.