【发布时间】:2019-06-17 08:23:54
【问题描述】:
我想用 xcopy 复制一个文件夹。但是,只要我将目标文件夹放在源文件夹中,就不会再复制任何内容。这个问题有解决办法吗?
这个想法是将整个文件夹结构(源)的备份生成到一个子文件夹中。执行 xcopy 时,我排除了备份(目标)的子文件夹,我的备份应该存储在其中。
我已经测试了我的代码,只要目标文件夹不在源文件夹中,它就可以正常工作。
代码是用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
代码正在执行,没有错误,但是当我检查目标文件夹时,没有文件被复制。
【问题讨论】: