Vbscript 使用wshshell执行两个函数
我执行了两个不同的函数(copy和zip)。我可以用一个wshshell脚本来完成吗?我试过了---- 虽然单独的程序,例如g=“xcopy”&h&“D:\y\/e”和g=“cmd/c cd D:\D&D:&winzip32.exe-min-a D:\a”可以工作,但它不能工作。Vbscript 使用wshshell执行两个函数,vbscript,Vbscript,我执行了两个不同的函数(copy和zip)。我可以用一个wshshell脚本来完成吗?我试过了---- 虽然单独的程序,例如g=“xcopy”&h&“D:\y\/e”和g=“cmd/c cd D:\D&D:&winzip32.exe-min-a D:\a”可以工作,但它不能工作。 很抱歉出现了格式问题。非常感谢您提供的任何帮助。我认为您无法让它以这种方式工作:&operator是命令行shell的一部分,而不是CreateProcess或ShellAPI框架的一部分 我认为有几种方法可以解决这个
很抱歉出现了格式问题。非常感谢您提供的任何帮助。我认为您无法让它以这种方式工作:&operator是命令行shell的一部分,而不是CreateProcess或ShellAPI框架的一部分 我认为有几种方法可以解决这个问题:
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
是否绝对有必要在vbscript中执行此操作?为什么不从批处理中运行它呢?考虑到您仍然有问题,这会更容易。实际上,代码是工具的一部分。这个工具是用vbscript和asp开发的。嘿,谢谢你的回复。但问题是我是个初学者,不熟悉wshshell编码。我从一个网站上获得了这段代码,但我不知道该如何使用它。请你详细说明一下,或者给我几行代码。我添加了一些示例代码。但很难说你真正需要什么。我建议你从周围众多的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