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:
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:
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.
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.
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 …
Good job!!I continued tinkering with my recursive sub, though its longer it finally works
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(FROM, V(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 …
Thanks Marc!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks