Garbled characters in compressed Japanese files

Source: Internet
Author: User
Article Title: Garbled characters in Japanese compressed files. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

I used a Japanese linux system. I collected a compressed file from my colleague yesterday. After decompression, the file name is messy (the content is displayed normally ). Google found the following on the internet because the default encoding method in windows is Shift-JIS. in linux, although the content can be displayed, the file name is garbled. The solution is quite simple. perl provides some methods to directly write a short program.

I will also give an example program for reference from other places. (The Archive: Zip module must be installed here)

#! /Usr/bin/perl

Use strict;

Use warnings;

Use Archive: Zip qw (: ERROR_CODES: CONSTANTS );

Use Encode qw/from_to /;

Use Getopt: Long;

Use DateTime;

Use DateTime: TimeZone: Local;

GetOptions ('list | L' => \ my $ mode_list );

If (scalar @ ARGV <1 ){

Print "Usage: $0 [-l] \ N ";

Exit 1;

}

My $ zipfile = shift @ ARGV;

My $ zip = Archive: Zip-> new ();

Unless ($ zip-> read ($ zipfile) = AZ_ OK ){

Die 'read error ';

}

Print "Archive: $ zipfile \ n ";

If ($ mode_list ){

Print < < p><>

Length Date Time Name

---------------------------

HERE

}

My $ total_size = 0;

My @ members = $ zip-> members ();

My $ members_count = scalar @ members;

Foreach my $ member (@ members ){

My $ filename = $ member-> fileName;

From_to ($ filename, 'cp932', 'utf8 ');

If ($ mode_list ){

My $ dt = DateTime-> from_epoch (

Epoch => $ member-> lastModTime

)-> Set_time_zone (DateTime: TimeZone: Local-> TimeZone ());

$ Total_size + = $ member-> uncompressedSize;

Printf "% 9d % s \ n ",

$ Member-> uncompressedSize,

$ Dt-> ymd ('-'). ''. sprintf ("% 02d", $ dt-> hour ). ':'. sprintf ("% 02d", $ dt-> min ),

$ Filename;

} Else {

Print "inflating: $ filename \ n ";

Unless (defined $ zip-> extractMember ($ member, $ filename )){

Warn "failed: $ filename \ n ";

}

}

}

My $ members_count_str = "$ members_count file". ($ members_count> 1? 'S ':'');

If ($ mode_list ){

Print < < p><>

---------------

HERE

Printf "% 9d % s \ n", $ total_size, $ members_count_str;

}

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.