Zipping a folder using 7-Zip from an asp page

穿精又带淫゛_ 提交于 2020-07-04 05:26:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!