问题
I am trying to zip a folder from an asp page. This is my code:
zipFolderName=folderName &"Zipped.zip"
command="cd C:\Program Files\7-Zip & "
command = command & "7z a -tzip " & zipFolderName & " """ & folderName & """"
Response.Write command
set objshell = Server.CreateObject("WScript.shell")
objShell.exec (command)
set objshell=nothing
The command that is written in the Response.Write
is
cd C:\Program Files\7-Zip & 7z a -tzip D:/saveAll/DocumentsZipped.zip "D:/saveAll/Documents"
When I run this command in a cmd window it works just fine. But my asp page shows an error:
WshShell.Exec error '80070002'
The system cannot find the file specified.
The error is on the objShell.exe command-line.
What am I doing wrong? Please help!
回答1:
You need to put C:\Program Files\7-Zip
between double quotes, because the path contains a space. Also, cd
and &
are CMD-builtins, so you need to run the command line in CMD
.
Change this:
command="cd C:\Program Files\7-Zip & "
into this:
command = "%COMSPEC% /c cd ""C:\Program Files\7-Zip"" & "
来源:https://stackoverflow.com/questions/62710114/vbscript-how-to-7zip-a-folder-instead-of-file