如果已在其他地方回答此问题,我们深表歉意。我正在努力理解其他论坛帖子上糟糕的书面英语,我真的很想了解发生了什么。
这段代码很好用。
dim FileSys, source, destination, WSNet, theDate, theTime, computerName
Set FileSys = CreateObject("Scripting.FileSystemObject")
Set WSNet = CreateObject("WScript.Network")
computerName = WSNet.computerName
theDate = Replace(Date, "/","-")
theTime = Replace(Time, ":",".")
source = "C:\source"
destination = "C:\destfolder"
if Not FileSys.FolderExists(destination) Then
WScript.echo "the destination: " & destination & " doesnt exist, it will now be created"
FileSys.Createfolder(destination)
FileSys.CopyFolder source, destination
Else
If FileSys.FolderExists(source) Then
FileSys.CopyFolder source, destination
Else
WScript.echo "ERROR: The source folder is not present, nothing will be copied"
End If
End If
然而,当我替换这一行时:
destination = "C:\destfolder"
像这样的东西:
destination = "C:\destfolder\" & computerName & "\" & theDate & "\" & theTime
我得到一个错误。“找不到路径”,即使我缩小范围并使用:
destination = "C:\destfolder\" & computerName
我犯了同样的错误。在 WScript.echo 行上,字符串按我的预期出现,例如
C:\destfolder\MYPC\22-05-2014\13.55.44
它似乎没有创建文件夹,问题似乎出在 FileSys.CreateFolder 方法上,有人可以帮忙吗?
PS - 我的总体目标是将一些日志文件从一个地方复制到另一个地方,但按日期和时间按文件夹名称排序。