This article is done by using RAR.EXE and CMD. EXE of these two files, in the ASP programming in the online compression and decompression of the Web site file function. The implementation method is simple, the program code is few, can use for reference in the practical programming. Especially in the case of owning your own server is extremely practical and convenient. The above program runs through Windows2000sever and IIS5.0.
First of all to upload a winrar decompression program, is winrar own decompression program, only need its core program RAR.EXE this file can be, in the WinRAR installation directory can be found. Then you want to upload a program that executes RAR.EXE CMD. EXE This is the Windows operating system program, in the system disk Winnt/system32 folder can be found. After uploading the two files, you need to write some program code to achieve compression and decompression.
may wish to realize the compression function file name is zip.asp, realizes the decompression function the file name is unzip.asp.
The program code contains the command line syntax for the WinRAR application, which is briefly described below:
WinRAR < command >-< switch 1>-< switch n> < compressed file > < file ...> <@ list file ...> < decompression path \>
command to WinRAR the character combination that is running to represent the feature.
Switch switching operations specify type, compression strength, compressed file type, and so on.
Compressed file name to be processed by the cabinet.
File name to be processed by the file.
A list file list file is a plain text that contains the name of the file you want to work with. The filename should be started in the first volume. You can add a comment after the//character is used in the list file. For example, you can include two column strings to create a backup.lst:c:\work\doc\*.txt//Backup Text document C:\WORK\IMAGE\*.BMP//Backup picture C:\work\misc and then run: WinRAR a backup @ Backup.lst You can specify both the normal file name and the list file name on the command line.
The decompression path is used in combination with the command e and X. Indicates the location where the extracted file was added. If the folder does not exist, it is created automatically.
Alphabetical command list:
A add file to compressed file C add compressed file comment
D remove file from compressed file E Extract compression from compressed file, ignore path
F Refresh files in compressed file I find a string in a compressed file
K Lock compressed file m move files and folders to compressed files
R repair damaged compressed files RC Rebuild lost volumes
RN Rename compressed file Rr[n] Add data recovery record
Rv[n] Create a recovery volume S[name] Convert a compressed file into a self-extracting file type
S-delete self-extracting module T test compressed file
U update file x from compressed file to extract compression from compressed file with full path name
In fact, the key point in the program code is to use Server.CreateObject ("WScript. Shell"To execute the Cmd.exe,cmd.exe run RAR.EXE the winrar command to perform the uncompressed and compressed files.
List of programs
Zip. ASP Program list:
<%
'The main folder contains Cmd.exe Rar.exe For example: Files to compress (*.mdb)
'The stored directory after compression is Main\data.rar
On Error Resume Next
Unzip_path=server.mappath ("Main") &""
Set WshShell = server. CreateObject ("WScript. Shell")
Issuccess = Wshshell.run ("WinRAR a"&unzip_path&"Data
"&unzip_path&"*.mdb", 1, False)
'WinRAR < command >-< switch 1>-< switch n> < compressed file > < file ...> <@ list file ...>
< decompression path \>
'Command: A-Add to compressed file
If issuccess = 0 Then
Response.Write"Command executed successfully!"
Else
Response.Write"Command execution failed! Insufficient permissions or the program cannot run"
End If
If Err.Number <> 0 Then
Response.Write"<p> Error Number:"& Err.Number
Response.Write"<p> reasons:"& Err.deScriptIon
Response.Write"<p> Error Source:"& Err.Source
Response.Write
End If
%>
UNZIP. ASP Program list:
<%
'The main folder contains Cmd.exe Rar.exe files to decompress (*.rar)
'After decompression, the storage directory is main
On Error Resume Next
Unzip_path=server.mappath ("Main") &""
Set WshShell = server. CreateObject ("WScript. Shell")
Issuccess = Wshshell.run ("WinRAR X-r-o+"&unzip_path&"*.rar
"&unzip_path&"", 1, False)
'WinRAR < command >-< switch 1>-< switch n> < compressed file > < file ...> <@ list file ...>
< decompression path \>
'Command: X-Unzip the file from the full path in the compressed file
'Switches:-R-Together with subfolders
'Switch:-o+-overwrite files that already exist
'Switch:-o--do not overwrite files that already exist
If issuccess = 0 Then
Response.Write"Command executed successfully!"
Else
Response.Write"Command execution failed! Insufficient permissions or the program cannot run"
End If
If Err.Number <> 0 Then
Response.Write"<p> Error Number:"& Err.Number
Response.Write"<p> reasons:"& Err.deScriptIon
Response.Write"<p> Error Source:"& Err.Source
Response.Write
End If
%>