I know I need to use recursion for this but I always struggle with it.
I have a FolderItem called source. It may or may not have any number of folders and files within. The folders may or may not contain more files and folders.
All I want to do is replicate the folder structure of source into a FolderItem called output. I don’t want to copy the files, just create new empty folders with the same names and structure as in the source FolderItem.
Example source folder contents:
-- blog
----personal
------test.html
-- about
----index.html
Desired output folder contents:
blog
--personal
about
Does anyone have any code they could share to solve this?
http://documentation.xojo.com/index.php/FolderItem has the code for recursively traversing a directory (the CopyFileOrFolder example) just modify it to not actually copy anything and only create directories.
The example @Tim Parnell links to helped a lot. Here’s what I came up with (for future use):
[code]Private Sub CopyFolder(source as Xojo.IO.FolderItem, destination as Xojo.IO.FolderItem)
/// -----------------------------------------------------------------------
’ Used to recursively copy a folder structure
/// -----------------------------------------------------------------------
Dim f, newDestination As Xojo.IO.FolderItem
If source.IsFolder Then
newDestination = destination.Child(source.Name)
newDestination.CreateAsFolder
For Each f in source.Children
If f.IsFolder Then CopyFolder(f, newDestination)
Next f
End If
End Sub[/code]