in reply to Re^2: encode files to utf-16 and then move
in thread encode files to utf-16 and then move
#!/usr/bin/perl use warnings; use strict; use File::Spec::Functions qw( catfile ); my $src_dir = "C:\\ROOT_DIR\\test1\\"; my $dst_dir = "C:\\ROOT_DIR\\test2\\"; opendir(my $dh, $srcdir) or die "Can't open dir $srcdir: $!\n"; while (defined(my $file = readdir($dh))) { next if /^\.\.?\z/; my $src_file = catfile($src_dir, $file); my $dst_file = catfile($dst_dir, $file); open(my $src_fh, "<:raw:perlio:encoding(UTF-8)", $src_file) or die("Can't open \"$src_file\": $!\n"); open(my $dst_fh, ">:raw:perlio:encoding(UTF-16)", $dst_file) or die("Can't open \"$dst_file\": $!\n"); print $dst_fh $_ while <$src_fh>; unlink($src_fh); } print "done.\n";
|
|---|