我有两个不同的功能(复制和压缩)到b执行。我可以用一个wshshell script.i试过----
Dim WshShell, oExec,g,h
h="D:\d"
g="xcopy " & h & " " & "D:\y\ /E & cmd /c cd D:\c & D: & winzip32.exe -min -a D:\a"
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(g)
Do While oExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo oExec.Status
它可以起作用。虽然是单独的程序,即g =“xcopy”& h& “”& “D:\ y \ / E”和g =“cmd / c cd D:\ d& D:& winzip32.exe -min -a D:\ a”有效。 我很抱歉格式化问题。任何帮助表示赞赏。
答案 0 :(得分:0)
我认为你不能这样做:& operator是命令行shell的一部分,而不是CreateProcess或ShellAPI框架的一部分。
我认为有几种方法可以解决这个问题:
这是一个示例代码,介绍如何复制文件夹,然后在VBScript中删除另一个文件夹:
Dim WshShell, oExec, oFS, oF
szSourcePath="c:\tmp\testfolderSrc"
szDestinationPath="c:\tmp\testfolderDest"
szDestinationZip="c:\tmp\final.zip"
bOverwrite=true
' Create objects
Set oFS = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
' cleanup target folder
if oFS.FolderExists(szDestinationPath) then
oFS.DeleteFolder szDestinationPath, true
end if
' Create target folder
set oF = oFS.CreateFolder(szDestinationPath)
' Copy content of the source folder to the target folder
oFS.CopyFolder szSourcePath & "\*", szDestinationPath, bOverwrite
' delete old zip
if oFS.FileExists("c:\myzip.zip") then
oFS.deleteFile("c:\myzip.zip")
end if
wshShell.CurrentDirectory = "c:\tmp\" ' set current directory to this
Set oExec = WshShell.Exec("c:\program files\winzip\winzip32.exe -min -a c:\myzip.zip" )
Do While oExec.Status = 0
WScript.Sleep 100
Loop