Skip to content

Instantly share code, notes, and snippets.

@henices
Created April 9, 2014 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save henices/10243394 to your computer and use it in GitHub Desktop.
Save henices/10243394 to your computer and use it in GitHub Desktop.
convert file name to utf-8
#! /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;
@genru
Copy link

genru commented Nov 5, 2015

great! how to use, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment