I want to copy a folder with xcopy. However, as soon as I place the destination folder in the source folder, nothing is being copied anymore. Is there a workaround for this problem?
The idea is to generate a backup of an entire folder strucutre (source) into one subfolder. When executing xcopy I exclude the subfolder for the backup (destination), where my backups should be stored.
I have already tested my code and it works just fine as long as the destination folder does no lie within the source folder.
The code is written with VBA.
Function CopyFolder(ByVal sourcePath As String, ByVal destinationPath As String, ByVal excludeFile As String)
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
' /e -> copys all subfolders including empty ones; /k -> retains the read-only attribute if existend
wsh.Run "xcopy " & sourcePath & " " & destinationPath & " /e /k /exclude:" & excludeFile, vbNormalFocus, waitOnReturn
End Function
The code is being executed with no error, but when I check the destination folder, no files haven been copied.