我有一个备份脚本,通过计划任务将副本从一台服务器复制到另一台服务器。大多数文件夹都可以复制。但是,有一个文件夹在名称中有一个空格,它会把整个事情搞砸。
这在目标服务器上运行(拉入数据)。
我尝试了各种逃脱模式,但都失败了。 (变量变暗,代码被截断)
sArchiveFolder = "D:\Backup\" & year(now) & "-" & month(now) & "-" & day(now) & "\"
sDataFolder = "\\Server\Share\System Library"
sDestFolder = sArchiveFolder & "System Library\"
Call subCopyFolder(fso, objShell, sDataFolder, sDestFolder)
sub subCopyFolder(fso, objShell, sDataFolder, sArchiveFolder)
dim iCounter, excludedDirs
if not(fso.folderexists(sArchiveFolder)) then
fso.createfolder(sArchiveFolder)
excludedDirs = " /XD Logs"
if(right(sDataFolder,7)="Library") then
'this fails
'sDataFolder = """"&sDataFolder&""""
'sArchiveFolder = """"&sArchiveFolder&""""
'so does this
'sDataFolder = chr(34)&sDataFolder&chr(34)
'sArchiveFolder = chr(34)&sArchiveFolder&chr(34)
end if
Dim sRoboCopyCommand
sRoboCopyCommand = "robocopy " & sDataFolder & " " & sArchiveFolder & " /E "& excludedDirs &" /R:5 /W:1 /log+:log.txt"
objShell.Run (sRoboCopyCommand)
end sub
如何正确逃避这一点?我还尝试将文字引号放在robocopy命令行中,这也打破了不需要引号的文件夹。
如代码中所述,我尝试了#34; 4引号方法"它在robocopy命令行中不起作用。
用4引号方法:
(剥离了与问题无关的私人内容,即完整路径和其他eXcludeD fodler)
答案 0 :(得分:0)
对于后验性:在源或目标路径中显然尾随反斜杠会导致robocopy
的参数处理混乱,因此需要在没有它们的情况下指定路径:
sArchiveFolder = "D:\Backup\" & year(now) & "-" & month(now) & "-" & day(now)
sDataFolder = "\\Server\Share\System Library"
sDestFolder = sArchiveFolder & "\System Library"
...
sRoboCopyCommand = "robocopy """ & sDataFolder & """ """ & sArchiveFolder & _
""" /E " & excludedDirs & " /R:5 /W:1 /log+:log.txt"
objShell.Run sRoboCopyCommand