Results 1 to 4 of 4

Thread: [RESOLVED] Create Folder within Folder

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Resolved [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

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: Create Folder within Folder

    It works.. Awesome!
    Thank you so much for your help.

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width