NAME

Win32::Unicode::File - Unicode string file utility.

SYNOPSIS

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;

DESCRIPTION

Win32::Unicode::File is Unicode string file utility.

METHODS

new([$mode, $file_name])

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
open($mode, $file_name)

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+
close()

like CORE::close.

$fh->close;

or

close $fh;
read($buff, $len)

Like CORE::read.

$fh->read(my $buff, $len) or die $!;

or

read $fh, my $buff, $len;
readline()

Like CORE::readline.

my $line = $fh->readline;
my @line = $fh->readline;

or my $line = readline $fh; my @line = <$fh>;

getc()

Like CORE::getc.

my $char = $fh->getc;

or

my $char = getc $fh;
print(@str)

Data write to file.

$fh->print(@str);
print $fh @str;
printf($format, @str)

Formatted data write to file.

$fh->printf('[%s]', $str);
printf $fh '%d', $str;
write(@str)

Data write to file. alias of $fh->print

$fh->write(@str);
seek($ofset, $whence)

Like CORE::seek.

$fh->seek(10, 1);

or

seek $fh, 1024, 2;
tell()

Like CORE::tell.

my $current = $fh->tell;

or

my $current = tell $fh;
eof()

Like CORE::eof.

if ($fh->eof) {
   # ...snip
}

or

if (eof $fh) {
   # ...snip
}
slurp()

Read all data from the file.

my $data = $fh->slurp;
binmode($layer)
$fh->binmode(':encoding(cp932)')

or

binmode $fh, ':raw :utf8';

Currently available now is only the layer below.

:raw
:utf8
:encoding(foo)
flock($operation)

Like CORE::flock

$fh->flock(2);
unlock()

equals to

$fh->flock(8);
error()

get error message.

$fh->error;
flush

flush buffers.

$fh->flush;
autoflush()

enable or dsabile autoflush.

$fh->autoflush;    # enable
$fh->autoflush(0); # disable
$fh->autoflush(1); # enable
printflush()

write after flush.

$fh->printflush('foobar');

same as

$fh->print('foobar') && $fh->flush;
getline()

Like IO::File::getline.

my $line = $fh->getline;
getlines()

Like IO::File::getlines.

my @$lines = $fh->getlines;
getpos()

Like IO::File::getpos.

my $pos = $fh->getpos;
setpos($pos)

Like IO::File::setpos.

my $pos = $fh->setpos(10);
opened()

Returns true if the object is currentry opened file, false otherwise.

say $fh->opened ? 1 : 0;

FUNCTIONS

unlinkW($file)

Like CORE::unlink.

unlinkW $file or die $!;
copyW($from, $to)

Like File::Copy::copy.

copyW $from, $to or die $!;
moveW($from, $to)

Like File::Copy::move.

moveW $from, $to or die $!;
renameW($from, $to)

Alias of moveW.

touchW($file)

Like shell command touch.

touchW $file or die $!;
statW($file || $fh || $dir || $dh)

Like CORE::stat.

my @stat = statW $file or die $!;
my $stat = statW $file or die $!;

or

my $fh = Win32::Unicode::File->new(r => $file);
my @stat = statW $fh or die $!;
my $stat = statW $fh or die $!;

or

my @stat = statW $dir or die $!;
my $stat = statW $dir or die $!;

or

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.

utimeW($atime, $mtime, $file || $fh)

Like CORE::utime.

my $rc = utime($atime, $mtime, $file, $fh);
file_type('attribute', $file_or_dir)

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
}
file_size($file)

Get file size. near -s $file

my $size = file_size $file;
die $! unless defined $size;
filename_normalize($filename)

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);

AUTHOR

Yuji Shimada <xaicron@cpan.org>

SEE ALSO

Win32::Unicode

Win32::Unicode::File

Win32::Unicode::Error

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.