Extract files across platforms using Perl

Source: Internet
Author: User
Our project has many testing platforms, including Windows and Linux. Linux provides an unzip command for decompression, but it is troublesome in windows. in Windows 2000, no command is provided to decompress the file. In XP, The unzip command is provided, but there is no such command in Vista.

This is very troublesome. You cannot simply Extract files by using the commands provided by the operating system. Therefore, I wrote a script to handle this need.

In Linux, I will not write it, as long as the unzip command is used, it is very simple.

The following describes the modules used to solve windows problems.
Perl provides an archive package to solve the problem of decompression and File compression.

I simply applied the package decompression function.

  1. #! /Usr/bin/perl-W
  2. My ($ File,$ Targetdir) = @ Argv;
  3. If(! Defined ($ Targetdir)){
  4. $ Targetdir=".";
  5. Print"Unzip $ file to current dir.../N";
  6. }Else{
  7. Print"Unzip $ file to $ targetdir.../N";
  8. }
  9. UseArchive: Extract;
  10. My$ Ar= Archive: extract->New(Archive =>$ File);
  11. My$ OK=$ Ar-> Extract (to =>$ Targetdir)Or Die;

This script is mainly used to extract the specified compressed file to the specified directory. If the directory is not specified, extract it to the current directory.

In this way, you only need to call the script when extracting files on various platforms, and you only need to provide the path. Instead of writing data based on the systemCode.

:-D.

Related Article

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.