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.Dire ctory.GetDirect ories', 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 12735
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |