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.
2 12699
The most efficient way would be to use recursivity: -
Private Function getAllFolders(ByVal directory As String) As String()
-
'Create object
-
Dim fi As New IO.DirectoryInfo(directory)
-
'Array to store paths
-
Dim path() As String = {}
-
'Loop through subfolders
-
For Each subfolder As IO.DirectoryInfo In fi.GetDirectories()
-
'Add this folders name
-
Array.Resize(path, path.Length + 1)
-
path(path.Length - 1) = subfolder.FullName
-
'Recall function with each subdirectory
-
For Each s As String In getAllFolders(subfolder.FullName)
-
Array.Resize(path, path.Length + 1)
-
path(path.Length - 1) = s
-
Next
-
Next
-
Return path
-
End Function
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 and no files are deleted in
the folder.
The peculiarity of this issue is that the files/subfolders cannot be
seen through the windows explorer...
|
by: Tom |
last post by:
How do you programatically get a list of subfolders in a folder?
Thanks!
Tom
|
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 all subfolders or is there
a better way?
Thanks!
|
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
|
by: Robertico |
last post by:
Is it possible to upload a complete folder including the subfolders using
PHP ?
Regards,
Robertico
| |
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 sizes etc.
But I can't find anything comparable in VB.NET or am I missing
something? All the examples I have found online are...
|
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 set to browse. Without using
the below page, I can browse the files. What did I miss?
thanks!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% set fs =...
|
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 handy, easy to
backup, and modularized.
My setup has not changed much over the years. As of now I have:
C:\apache2.2
C:\mysql
C:\Php
|
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 uniformity.
I'd like to have the capability to find the file based on name, whether it's in a main folder, or one of the subfolders.
I.e. - File...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |