Skip to main content

List of Sub-Folders

I am using the getFolder function, and now I want to write the list of sub directory's to an array.
Does anyone know of a simple way of doing this?
Reason for the script... I receave 18 seperate files per day, which I save in a directory by the day (e.g. Jan 1). I would like to tell IDEA to look in the Jan 1 folder, then write all the sub-directories to an array. I would then use that array as part of the script to import the files, and the append them all together.
Any assistance is appreciated
Edward

Brian Element Sat, 05/31/2014 - 09:01

Hi Edward, you can try something like this.  Replace the "c:\" with the location of the top folder.

Sub Main
	Dim fso As Object
	Dim folder As Object
	Dim subFlds As Object
	Dim fld As Object
	Dim aFolders() As String
	Dim bFirstTime As Boolean
	
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set folder = fso.GetFolder("c:\")
	Set subFlds = folder.SubFolders
	bFirstTime = True
	For Each fld In subFlds
		If bFirstTime Then
			ReDim aFolders(0)
			bFirstTime = False
		Else
			ReDim Preserve aFolders(UBound(aFolders) + 1)
		End If
		aFolders(UBound(aFolders)) = fld.name
	Next 
	
	Set fld = Nothing
	Set subFlds = Nothing
	Set folder = Nothing
	Set fso = Nothing
End Sub