FolderItem.CopyTo
From Xojo Documentation
Method
FolderItem.CopyTo(destination as FolderItem)
New in 2019r2.1
Supported for all project types and targets.
New in 2019r2.1
Supported for all project types and targets.
If the FolderItem is a folder, then the folder and its contents are copied into destination.
Notes
If destination is a file and the file already exists, the copy is cancelled. You need to delete the existing file first. If there is an error, an IOException is raised.
On Xojo Cloud, FolderItems that are copied using CopyTo cannot have their permissions changed. For now, the workaround is to use a Shell command to alter the permissions:
Sample Code
The following example method copies a source FolderItem to a new destination using CopyTo. It returns True if all files in the folder were successfully copied and returns False otherwise.
Function CopyFileOrFolder(source As FolderItem, destination As FolderItem) As Boolean
Var newFolder As FolderItem
If source.IsFolder Then // it's a folder
newFolder = destination.Child(source.Name)
newFolder.CreateFolder
If Not newFolder.Exists Or Not newFolder.IsFolder Then
// folder was not created - stop processing
Return False
End If
For Each file As FolderItem In source.Children
If file = Nil Then
// inaccessible
Return False
End If
If Not CopyFileOrFolder(file, newFolder) Then
// copy operation failed
Return False
End If
Next
Else // it's not a folder
source.CopyTo(destination)
If source.LastErrorCode <> 0 Then
Return False
End If
End If
Return True
End Function
Var newFolder As FolderItem
If source.IsFolder Then // it's a folder
newFolder = destination.Child(source.Name)
newFolder.CreateFolder
If Not newFolder.Exists Or Not newFolder.IsFolder Then
// folder was not created - stop processing
Return False
End If
For Each file As FolderItem In source.Children
If file = Nil Then
// inaccessible
Return False
End If
If Not CopyFileOrFolder(file, newFolder) Then
// copy operation failed
Return False
End If
Next
Else // it's not a folder
source.CopyTo(destination)
If source.LastErrorCode <> 0 Then
Return False
End If
End If
Return True
End Function