Created
April 9, 2014 08:50
-
-
Save henices/10243394 to your computer and use it in GitHub Desktop.
convert file name to utf-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/perl -w | |
# rename the gbk filename to utf-8 | |
use strict; | |
use Encode; | |
my $dir = $ENV{'PWD'}; | |
opendir DIR, $dir or die "Can not open \"$dir\"\n"; | |
my @filelist = readdir DIR; | |
my $file = ''; | |
for $file (@filelist) | |
{ | |
chomp $file; | |
if ($file ne '.' && $file ne '..') | |
{ | |
my $utf8str = encode("utf-8", decode("gbk",$file)); | |
chomp $utf8str; | |
`mv "$file" "$utf8str"`; | |
} | |
} | |
closedir DIR; | |
@filelist = (); | |
opendir DIR, $dir or die "Can not open \"$dir\"\n"; | |
@filelist = readdir DIR; | |
for $file (@filelist) | |
{ | |
print "$file\n"; | |
} | |
closedir DIR; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great! how to use, please.