【发布时间】:2014-07-11 12:49:34
【问题描述】:
如果这已在其他地方得到回答,我们深表歉意。我很难理解其他论坛帖子上糟糕的书面英语,我真的很想了解发生了什么。
这段代码很好用。
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 - 我的总体目标是将一些日志文件从一个地方复制到另一个地方,但按日期和时间按文件夹名称排序。
【问题讨论】:
标签: vbscript filesystemobject create-directory