如果这个问题在其他地方得到了回答,我深表歉意。我正在努力理解其他论坛帖子上糟糕的书面英语,我真的很想知道发生了什么。
这段代码运行得很好。
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 -我在这里的总体目标是将一些日志文件从一个地方复制到另一个地方,但要按文件夹名称的日期和时间进行排序。
发布于 2014-05-22 21:26:25
CreateFolder方法只能创建一级深的文件夹。
您将需要这样做(这只是一个改进空间的example...lots ):
destination = "C:\destfolder"
FileSys.Createfolder(destination)
FileSys.Createfolder(destination & "\" & computerName)
FileSys.Createfolder(destination & "\" & computerName & "\" & theDate)
FileSys.Createfolder(destination & "\" & computerName & "\" & theDate & "\" & theTime)或者,您可以创建一个函数,该函数将一次创建多个文件夹。执行此操作的函数的Here is an example。
发布于 2014-05-23 08:56:13
正如@aphoria提到的,CreateFolder()一次只能创建一个级别。但是,您可以调用mkdir命令在一次调用中创建整个文件夹结构。
With CreateObject("WScript.Shell")
.Run "cmd /c mkdir ""c:\destfolder\" & computerName & "\" & theDate & "\" & theTime & """", 0, True
End With将0作为第二个参数传递,以防止命令提示符窗口在屏幕上闪烁。
将True作为第三个参数传递,让您的脚本等到命令完成后再继续。
https://stackoverflow.com/questions/23807562
复制相似问题