+ Reply to Thread
Results 1 to 7 of 7

Replicating a folder structure using fso

  1. #1
    Registered User
    Join Date
    07-19-2018
    Location
    harare
    MS-Off Ver
    2013
    Posts
    20

    Replicating a folder structure using fso

    I want to copy the folder structure from one directory to another(with subfolders), but I seem to be lost in the recursion. May you kindly assist



    HTML Code: 

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,922

    Re: Replicating a folder structure using fso

    Could you use Xcopy?

    /T switch copies folders only, not files.
    /E switch includes copying empty folders.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-19-2018
    Location
    harare
    MS-Off Ver
    2013
    Posts
    20

    Re: Replicating a folder structure using fso

    Thanks, ByteMarks for an elegant solution, it works! I continued tinkering with my recursive sub, though its longer it finally works lol..
    HTML Code: 
    Last edited by gringol; 06-20-2021 at 12:16 PM.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Replicating a folder structure using fso


    Hi,

    as it could be also achieved with or without FSO and without any recursion (another way than the classic xcopy DOS command)
    creating a complete sub folder path at once via a Windows API, a longer code but quick to execute …

  5. #5
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    365 32bit Win
    Posts
    1,922

    Re: Replicating a folder structure using fso

    I continued tinkering with my recursive sub, though its longer it finally works
    Good job!!

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this …


    Another VBA demonstration playing with FSO & recursion to paste to the top of a module
    for Excel 2010 & upper Windows versions only whatever 32 or 64 bits (for previous Excel versions just remove PtrSafe) :

    PHP Code: 
    Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath$) As Boolean

    Dim V
    (2)

    Sub MakeDeepFolders(FROM)
                     
    Dim oF As Object
        With V
    (2).GetFolder(FROM)
            If .
    SubFolders.Count Then
                
    For Each oF In .SubFolders:  MakeDeepFolders oF.Path:  Next
            
    Else
                
    MakeSureDirectoryPathExists Replace(FROMV(0), V(1)) & Application.PathSeparator
            End 
    If
        
    End With
    End Sub

    Sub Demo1
    ()
              
    V(0) = "C:\Users\Dell\Source"
              
    V(1) = Environ("UserProfile") & "\Desktop\Destination"
          
    Set V(2) = CreateObject("Scripting.FileSystemObject")
           If 
    V(2).FolderExists(V(0)) Then MakeDeepFolders V(0) Else Beep
        Erase V
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 06-21-2021 at 09:52 AM. Reason: typo …

  7. #7
    Registered User
    Join Date
    07-19-2018
    Location
    harare
    MS-Off Ver
    2013
    Posts
    20

    Re: Try this …

    Thanks Marc!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create folder structure from Excel
    By bikidunker in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2014, 03:18 PM
  2. Replies: 2
    Last Post: 10-17-2013, 02:49 PM
  3. Create folder path from tree structure
    By ironaces in forum Excel General
    Replies: 6
    Last Post: 02-22-2012, 04:52 AM
  4. Import folder structure in Outlook mailbox
    By Toomay in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 08-14-2011, 05:45 PM
  5. Macro that can search folder structure
    By Traymond in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2011, 07:11 PM
  6. folder structure by shell
    By trucker10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2009, 11:59 AM
  7. Excel files replicating and renaming in a folder
    By hpum in forum Excel General
    Replies: 0
    Last Post: 07-21-2007, 09:23 AM
  8. replicating a folder hiearchy.
    By Rodney in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 12-08-2005, 11:10 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1