[RESOLVED] Create Folder within Folder
I have a directory that is structured similar to this:
Code:
-Root
-Folder1
-SubFolder1
-Folder2
-SubFolder2
What I'm trying to do is place a folder named "2010" within each of the subfolders. There are a couple hundred of the subfolders and I do not have the name of each of these folders. All I know is that the subfolders are 2 deep from the root directory. Is there a way I can generically open the subfolders and create the "2010" folder?
Any help is appreciated.
Thanks,
Chrissy
Re: Create Folder within Folder
Code:
'~~> Please set a reference to Microsoft Scripting Runtime Library
'~~> Tested with this directory structure.
'C:\Temp\1
'C:\Temp\1\a
'C:\Temp\2
'C:\Temp\2\b
'C:\Temp\3
'C:\Temp\3\c
'~~> OUTPUT
'C:\Temp\1\a\2010
'C:\Temp\2\b\2010
'C:\Temp\3\c\2010
Private Sub Create2010Folder()
'~~> Your Base Folder
sFolderPath = "C:\Temp"
Dim FS As New FileSystemObject, i As Integer, MyArray() As String
Dim FSfolder As Folder, subfolder As Folder
Dim FS1folder As Folder, sub1folder As Folder
Set FSfolder = FS.GetFolder(sFolderPath)
For Each subfolder In FSfolder.SubFolders
DoEvents
Set FS1folder = FS.GetFolder(subfolder & "\")
For Each sub1folder In FS1folder.SubFolders
i = i + 1
ReDim Preserve MyArray(i)
MyArray(i - 1) = sub1folder
Next
Next subfolder
Set FSfolder = Nothing
Set FS1folder = Nothing
For i = 0 To UBound(MyArray) - 1
'~~> Create Directories
MkDir MyArray(i) & "\2010"
Next
End Sub
Re: Create Folder within Folder
It works.. Awesome!
Thank you so much for your help.
Re: [RESOLVED] Create Folder within Folder
You are welcome :)
Remember, I have not done any error handling. I would recommend that you do not forget to do that ;)