建站代码网

热门标签

怎样用ASP压缩文件


多数的时候我们需要压缩文件,保存到特定的位置,或者你可以使用它实现所有你想要的效果。
我们需要服务器支持Wscript.Shell-多数的站长都不会允许这样的。
这里你可以获取下载链接,在下载这个文件之前你可以要么指定相对的路径或者是绝对的路径,然后点击这里下载。
-zipfile.asp

< % '--------------------------------------------------------- 'CreateZipFile: function to create zip file at particular location 创建Zip文件:在特定位置zip文件的功能 'ZipPath - full path for the zip file, including the zip file name. Zip路径--zip文件的完整路径,包括zip文件名 'arrFilesPath - array of the files to be zipped, arr文件路径—被压缩文件的排列组 e.g. Array("C:*.exe", "C:foldername*.*") 注意:这个代码需要在相同位置的ZIP.EXE效果。 正如这个文件 '--------------------------------------------------------- Sub CreateZipFile(ZipPath, arrFilesPath) Const PKZIP_FILE_NAME="zip.exe" Dim strCommand, objShell, objFSO Dim x
首先检查zip.exe文件里面的:

Set objFSO=Server.CreateObject("scripting.FileSystemObject") If Not(objFSO.FileExists(Server.MapPath(ZIP_FILE_NAME) )) Then Set objFSO=Nothing Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(ZIP_FILE_NAME) End If

删除当前的文件:

If objFSO.FileExists(ZipPath) Then objFSO.DeleteFile(ZipPath) End If Set objFSO=Nothing
批量命令:

strCommand=Server.MapPath(ZIP_FILE_NAME)&" -add "&ZipPath&" " For x=0 To UBound(arrFilesPath) strCommand=strCommand&arrFilesPath(x) If x < UBound(arrFilesPath) Then strCommand=strCommand&" " Next 执行: Set objShell=Server.CreateObject("Wscript.Shell") objShell.Run strCommand, 0, True 'wait! 完成: Set objShell=Nothing End Sub %> now u can call your CreateZipFile() function -checkZipFile.asp < % Call checkZipFile() Sub checkZipFile() 创建zip和给出链接: Call CreateZipFile(Server.MapPath("Testzip.zip"), Array(Server.MapPath("images")&"*.*")) Response.Write("click here download zip") End Sub %>

X