Is there some slick way to copy a file and maintain the folder structure it came from?
I have an array with path and file names, I loop through this list and use FolderItem.CopyTo to copy the files. But it copies the files to the root of the destination location.
With pure Xojo code you would have to create each level of the file system within the application. For example you would have to create folder1 and then folder2 within it and folder3 within that and then copy your file.
Alternately you could use a shell script and rsync on a Mac to achieve the same thing.
Your array structure is not ideal for representing the structure you want to create. You really want a tree structure that mimics the tree structure of the file system. Then you can traverse the input tree structure and use recursion to create the output tree structure of folders and files.
My tree structure for this sort of thing is in an SQLite database.
thanks everyone. i know it is not ideal, i will try the split idea from Markus. my question was more around knowing if this problem had been solved in some way that is way more clever than what i will ever achieve!
I always take from this forum, so glad for an opportunity to give back. here is the function i wrote to recursively create the folders of a path you provide. Might not be the best way, my brain thinks in (various flavours of) BASIC.
Sub CreateFolderRecursive(path As String)
Var x As FolderItem
Var pathDir as String
If TargetLinux Then
pathDir = ""
For Each dir as String in path.Split("/")
If dir.Length > 0 Then
If pathDir <> "" Then pathDir = pathDir + "/" Else pathDir = "/"
pathDir = pathDir + dir
x = New FolderItem(pathDir)
If x.Exists = False Then x.CreateFolder()
End If
Next
End If
End Sub