
Win32::Unicode::Dir - Unicode string directory utility.

use Win32::Unicode::Dir;
use Win32::Unicode::Console;
my $dir = "I \x{2665} Perl";
my $wdir = Win32::Unicode::Dir->new;
$wdir->open($dir) || die $wdir->error;
for ($wdir->fetch) {
next if /^\.{1,2}$/;
my $full_path = "$dir/$_";
if (file_type('f', $full_path)) {
# $_ is file
}
elsif (file_type('d', $full_path))
# $_ is directory
}
}
$wdir->close || dieW $wdir->error;
my $cwd = getcwdW();
chdirW($change_dir_name);
mkdirW $dir;
rmdirW $dir;

Win32::Unicode::Dir is Unicode string directory utility.

Create a Win32::Unicode::Dir instance.
my $wdir = Win32::Unicode::Dir->new;
Like CORE::opendir.
$wdir->open($dir) or die $!
Like CORE::readdir.
while (my $file = $wdir->fetch) {
# snip
}
or
for my $file ($wdir->fetch) {
# snip
}
Alias of fetch().
Alias of fetch().
Like CORE::closedir.
$wdir->close or dieW $wdir->error
get error message.

Like Cwd::getcwd. get current directory.
my $cwd = getcwdW;
Like CORE::chdir.
chdirW $dir or die $!;
Like CORE::mkdir.
mkdirW $new_dir or die $!;
Like CORE::rmdir.
rmdirW($del_dir) or die $!;
Like File::Path::rmtree.
rmtreeW $del_dir or die $!;
Like File::Path::mkpath.
mkpathW $make_long_dir_name or die $!
copy directory tree.
cptreeW $from, $to or die $!;
If $from delimiter of directory is a terminator, move the contents of $from to $to.
cptreeW 'foo/', 'hoge'; # before current directory tree # ---------------------------- # foo # foo/bar # foo/bar/baz # hoge # ---------------------------- # before current directory tree # ---------------------------- # foo # foo/bar # foo/bar/baz # hoge/ # hoge/bar # hoge/bar/baz # ----------------------------
If just a directory name, is as follows
cptreeW 'foo', 'hoge'; # before current directory tree # ---------------------------- # foo # foo/bar # foo/bar/baz # hoge # ---------------------------- # before current directory tree # ---------------------------- # foo # foo/bar # foo/bar/baz # hoge/foo # hoge/foo/bar # hoge/foo/bar/baz # ----------------------------
move directory tree.
mvtreeW $from, $to or die $!;
If $from delimiter of directory is a terminator, move the contents of $from to $to.
mvtreeW 'foo/', 'hoge'; # before current directory tree # ---------------------------- # foo # foo/bar # foo/bar/baz # hoge # ---------------------------- # after current directory tree # ---------------------------- # foo # hoge # hoge/bar # hoge/bar/baz # ----------------------------
If just a directory name, is as follows
mvtreeW 'foo', 'hoge'; # before current directory tree # ---------------------------- # foo # foo/bar # foo/bar/baz # hoge # ---------------------------- # after current directory tree # ---------------------------- # hoge # hoge/foo # hoge/foo/bar # hoge/foo/bar/baz # ----------------------------
like File::Find::find.
findW \&wanted, $dir;
sub wanted {
my $file = $_;
my $name = $Win32::Unicode::Dir::name;
my $dir = $Win32::Unicode::Dir::dir;
my $cwd = $Win32::Unicode::Dir::cwd; # $dir eq $cwd
}
or
findW \&wanted, @dirs;
sub wanted{
my $arg = shift;
print $args->{file}; # eq $_
print $args->{name}; # eq $Win32::Unicode::Dir::name
print $args->{cwd}; # eq $Win32::Unicode::Dir::cwd
print $args->{dir}; # eq $Win32::Unicode::Dir::dir
print $args->{path}; # full path
}
or
findW \%options, @dirs;
wantedThe value should be a code reference. Like File::Find#wanted
preprocessThe value should be a code reference. Like File::Find#preprocess
postprocessThe value should be a code reference. Like File::Find#postprocess
no_chdirBoolean. If you set a true value will not change directories. In this case, $_ will be the same as $Win32::Unicode::Dir::name. Like File::Find#no_chdir
like File::Find::finddepth.
finddepthW \&wanted, $driname;
equals to
findW { wanted => \&wanted, bydepth => 1 }, $dirname;
get directory size. this function are slow.
my $dir_size = dir_size($dir) or die $!
get files from $dir
my @files = file_list $dir;
get directories from $dir
my @dirs = dir_list $dir;

Yuji Shimada <xaicron@cpan.org>


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