Use WinRAR in VB for file compression

zhaozj2021-02-11  206

Author: Limei database files (such as Access file) in remote file transfer process may be due to relatively large impact transfer effect. If it is transmitted, it will be transmitted, and the delivery time is reduced, avoiding accidental occurrence, and also guarantees the transmission effect. When we compress file, the most commonly used compression tool is WinRAR and Winzip, the author uses the WinRAR tool in the VB programming process to compress the database file, and complete the remote transfer, very convenient, here to introduce you. Similar to Winzip method. First, the shell function shell function is the internal function in VB, which is responsible for executing an executable file, returns a variant (double), if successful, representing the process ID of this program, if it is not successful, it will return 0. SHELL's grammar: shell (Pathname [, WindowStyle]). Pathname is a required parameter. The type is String, which points out the program name to be executed, and any required parameters or command line variables, or the path name can also be included. WindowStyle is an optional parameter. Integer type, specify the style of the program running window. WindowStyle has the following values. A constant value describes the VBHIDE 0 window is hidden, and the focus will be moved to the implicit window. The VBNORMALFOCUS 1 window has focus and reduces it to its original size and location. The VBMinimizedFocus 2 window displays (default) with an icon with focus. The VBMaximizedFocus 3 window is a maximum window with focus. The VBNORMALNOFOCUS 4 window will be restored to the most recently used size and location, while the currently active window remains active. The VBMinimizednofocus 6 window will display with an icon, while the currently active window remains active. 2. About WinRAR usage mainly describes how to compress and decompress files with the command line in WinRAR. Compression: WinRAR A [-switches]

[Files] [@file lists]

For example, you want to compress the try.mdb to the C drive, you can WinRar a c: try.rar C: try.mdb

Unzip: If the directory decompressed

WinRAR X [-switches]

[Files] [@file lists] [DESTION OFOLDER]

If you decompress in the current directory, you don't write a directory name when you decompression.

Winrar e [-switches]

[Files] [@file lists] [DESTION OFOLDER]

For example, you want to extract TRY.rar under the C drive, you can WinRar X C: TRY.RAR C: try.mdb

Three, one example

Create a new project in VB, add two buttons for Command1, Command2, and Command3 in Form1, and set their CAPTION attribute to "Compressed File", "Unpacking File" and "Pass". Complicate the file Try.mdb into TRY.rar when tap according to Command1.

Private submmand1_click ()

DIM RAREXE AS STRING 'WinRAR execution file location

Dim Source as string 'The original file before compression

DIM Target as string 'After compressed target file

DIM FILESTRING AS STRING 'SHELL in the instruction

Dim Result As Long

RAREXE = "C: Program FileswinRarwinrar"

Source = "c: try.mdb" target = "c: try.ra"

FILESTRING = RAREXE & "A" & Target & "& SOURCE

Result = shell (filestring, vbhide)

End Sub

The process of extracting is similar, and trying the try.rar to generate TRY.MDB by pressing the TRY.rar. After performing the above compression process, you can delete the file try.mdb to decompress the regeneration TRY.mdb.

Private sub fascist2_click ()

DIM RAREXE AS STRING 'WinRAR execution file location

Dim Source as string 'Unexpected original file

Dim target as string 'decompressed target file

DIM FILESTRING AS STRING 'SHELL in the instruction

Dim Result As Long

RAREXE = "C: Program FileswinRarwinrar"

Source = "C: TRY.Rar"

Target = "c: try.mdb"

FILESTRING = RAREXE & "X" & SOURCE & "& Target

Result = shell (filestring, vbhide)

End Sub

Before you transfer from a computer to another computer, you should know the name of another computer, and then use the filecopy statement. Suppose it is to pass the compressed try.rar to the shared directory "Want" of the computer name "Other".

Private submmand3_click ()

DIM Sourcefile, DestinationFile

Sourcefile = "c: try.rar" 'Specifies the source file name.

DestinationFile = "OtherWantTry.rar" 'Specifies the file name of the destination.

FileCopy Sourcefile, DestinationFile 'Copy the contents of the source file into the destination file.

End Sub

How is it, very simple?

转载请注明原文地址:https://www.9cbs.com/read-5014.html

New Post(0)