I have a question about using Wscript. Shell compression. thank you!

Source: Internet
Author: User
If you want to use Wscript. Shell for compression, thank you. & lt ;? PHPclass & nbsp; rar {public & nbsp; $ Path; & nbsp; // file Path public & nbsp; $ Save; & nbsp; // Save Path public & nb Wscript. shell compression. thank you!

Class rar
{

Public $ Path; // file Path

Public $ Save; // Save path

Public $ Object; // Wscript. Shell Object instance

Function rar () {// Constructor

$ This-> Object = new com ("Wscript. Shell"); // instantiate a Shell Object

}

Function Release () {// decompression method

$ This-> Object-> run ("WinRAR x $ this-> Path $ this-> Save", 1, false ); // Save the file name and Path to be decompressed in Path

If ($ this-> Object = true ){

Return true;

} Else {

Return false;

}

}

Function Pressure () {// compression method

$ This-> Object-> run ("WinRAR a $ this-> Save $ this-> Path", 1, true ); // Save the compressed Path and the file name Path to be compressed

If ($ this-> Object = true ){

Return true;

} Else {

Return false;

}

}
}


$ Rar = new rar ();
$ Rar-> Path = "F:/js/test/z.rar ";
$ Rar-> Save = "F:/js/test ";
If ($ rar-> Release ()){
Die ('decompressed successfully ');
} Else {
Die ('decompression failed ');
}
?>
 



This code can be compressed normally.
However, it can only compress absolute paths, and it adds all directories to empty folders during compression.
For example, I compress: c: \ a \ B \ c \ k.txt
The compressed file contains many layers of folders.
-
-B
-C
-K.txt
What should I do?
The relative directory cannot be compressed.
------ Solution --------------------
You can add the following parameters to winrar, but you must be clear about the consequences.

Ep exclusion path from name

When this switch is included, the file will not contain path information when it is added to the compressed file. This may result in several results with the same name in the compressed file.

Ed does not add an empty directory

This switch indicates that the empty directory is not stored in the created compressed file. When extracting such a compressed file, RAR will create a non-empty directory based on their internal file path. Information about empty directories is lost. Non-empty directories except names (access permissions, streams, and so on .) All other attributes are lost, so this switch is used only when you do not need to retain such information.


------ Solution --------------------
$ This-> Object-> run ("WinRAR a parameter here $ this-> Save $ this-> Path", 1, true );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.