Zipping a folder using 7-Zip from an asp page

2019-08-02 01:30发布

问题:

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"" & "