Win32::Unicode::File - Unicode string file utility.
use Win32::Unicode::File; my $file = "I \x{2665} Perl"; unlinkW $file or die $!; copyW $from, $to or die $!; moveW $from, $to or die $!; file_type f => $file ? "$file is file" : "$file is not file"; my $size = file_size $file; touchW $new_file;
Win32::Unicode::File is Unicode string file utility.
Crate a new Win32::Unicode::File instance. At the same time you can open the file to create an instance.
my $fh = Win32::Unicode::File->new; my $fh = Win32::Unicode::File->new($mode, $file_name); # create an instance and open the file
like CORE::open, but compatibility is not an argument. can not be pipe open.
$fh->open('<', $file_name) or die $!;
or
open $fh, '<', $file_name or die $!;
Be useful mode
< = r = rb > = w = wb >> = a +< = r+ +> = w+ +>> = a+
like CORE::close.
$fh->close;
close $fh;
Like CORE::read.
$fh->read(my $buff, $len) or die $!;
read $fh, my $buff, $len;
Like CORE::readline.
my $line = $fh->readline; my @line = $fh->readline;
or my $line = readline $fh; my @line = <$fh>;
Like CORE::getc.
my $char = $fh->getc;
my $char = getc $fh;
Data write to file.
$fh->print(@str); print $fh @str;
Formatted data write to file.
$fh->printf('[%s]', $str); printf $fh '%d', $str;
Data write to file. alias of $fh->print
$fh->write(@str);
Like CORE::seek.
$fh->seek(10, 1);
seek $fh, 1024, 2;
Like CORE::tell.
my $current = $fh->tell;
my $current = tell $fh;
Like CORE::eof.
if ($fh->eof) { # ...snip }
if (eof $fh) { # ...snip }
Read all data from the file.
my $data = $fh->slurp;
$fh->binmode(':encoding(cp932)')
binmode $fh, ':raw :utf8';
Currently available now is only the layer below.
:raw :utf8 :encoding(foo)
Like CORE::flock
$fh->flock(2);
equals to
$fh->flock(8);
get error message.
$fh->error;
flush buffers.
$fh->flush;
enable or dsabile autoflush.
$fh->autoflush; # enable $fh->autoflush(0); # disable $fh->autoflush(1); # enable
write after flush.
$fh->printflush('foobar');
same as
$fh->print('foobar') && $fh->flush;
Like IO::File::getline.
IO::File::getline
my $line = $fh->getline;
Like IO::File::getlines.
IO::File::getlines
my @$lines = $fh->getlines;
Like IO::File::getpos.
IO::File::getpos
my $pos = $fh->getpos;
Like IO::File::setpos.
IO::File::setpos
my $pos = $fh->setpos(10);
Returns true if the object is currentry opened file, false otherwise.
say $fh->opened ? 1 : 0;
Like CORE::unlink.
unlinkW $file or die $!;
Like File::Copy::copy.
copyW $from, $to or die $!;
Like File::Copy::move.
moveW $from, $to or die $!;
Alias of moveW.
Like shell command touch.
touch
touchW $file or die $!;
Like CORE::stat.
my @stat = statW $file or die $!; my $stat = statW $file or die $!;
my $fh = Win32::Unicode::File->new(r => $file); my @stat = statW $fh or die $!; my $stat = statW $fh or die $!;
my @stat = statW $dir or die $!; my $stat = statW $dir or die $!;
my $dh = Win32::Unicode::Dir->new->open($dir); my @stat = statW $dh or die $!; my $stat = statW $dh or die $!;
If the array context, CORE:: stat like. However, scalar context case in hashref received.
Like CORE::utime.
my $rc = utime($atime, $mtime, $file, $fh);
Get windows file type
# attributes f => file d => directory e => exists s => system r => readonly h => hidden a => archive n => normal t => temporary c => compressed o => offline i => not content indexed E => encrypted if (file_type d => $file_ro_dir) { # snip } elsif (file_type fr => $file_or_dir) { # file type 'file' and 'readonly' # snip }
Get file size. near -s $file
-s $file
my $size = file_size $file; die $! unless defined $size;
Normalize the characters are not allowed in the file name. not export.
use Win32::Unicode::File qw(filename_normalize); my $nomalized_file_name = filename_normalize($filename);
Yuji Shimada <xaicron@cpan.org>
Win32::Unicode
Win32::Unicode::File
Win32::Unicode::Error
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Win32::Unicode, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::Unicode
CPAN shell
perl -MCPAN -e shell install Win32::Unicode
For more information on module installation, please visit the detailed CPAN module installation guide.