|
NAMEPath::Extended::DirSYNOPSISuse Path::Extended::Dir; my $dir = Path::Extended::Dir->new('path/to/dir'); my $parent_dir = Path::Extended::Dir->new_from_file('path/to/some.file'); # you can get information of the directory print $dir->basename; # dir print $dir->absolute; # /absolute/path/to/dir # you can get an object for the parent directory or children my $parent_dir = $dir->parent; my $sub_dir = $dir->subdir('path/to/subdir'); my $sub_file = $dir->file('path/to/file'); # Path::Extended::Dir object works like a directory handle $dir->open; while( my $entry = $dir->read ) { print $entry->basename, "\n"; } $dir->close; # it also can do some extra file related tasks $dir->copy_to('/other/path/to/dir'); $dir->unlink if $dir->exists; $dir->mkdir; $dir->recurse(prune => 1, callback => sub { my $entry = shift; # Path::Extended::File/Dir object return if $entry->is_dir; print $entry->slurp; }); foreach my $file ( $dir->find('*.txt') ) { print $file->relative, "\n"; } # it has a logger, too $dir->log( fatal => "Couldn't open $dir: $!" ); DESCRIPTIONThis class implements several directory-specific methods. See also Path::Class::Entity for common methods like copy and move.METHODSnew, new_from_filetakes a path or parts of a path of a directory (or a file in the case of "new_from_file"), and creates a Path::Extended::Dir object. If the path specified is a relative one, it will be converted to the absolute one internally.basenamereturns the last part of the directory.open, close, read, seek, tell, rewindare simple wrappers of the corresponding built-in functions (with the trailing 'dir').mkdir, mkpathmakes the directory via "File::Path::mkpath".rmdir, rmtree, removeremoves the directory via "File::Path::rmtree".find, find_dirtakes a File::Find::Rule's rule and a hash option, and returns "Path::Extended::*" objects of the matched files ("find") or directories ("find_dir") under the directory the $self object points to. Options are:
nextwhile (my $file = $dir->next) { next unless -f $file; $file->openr or die "Can't read $file: $!"; ... } returns a Path::Extended::Dir or Path::Extended::File object while iterating through the directory (or "undef" when there's no more items there). The directory will be open with the first "next", and close with the last "next". childrenreturns a list of Path::Extended::Class::File and/or Path::Extended::Class::Dir objects listed in the directory. See Path::Class::Dir for details.As of 0.13, this may take a "prune" option to exclude some of the children. See below for details. file, subdirreturns a child Path::Extended::Class::File/Path::Extended::Class::Dir object in the directory.file_or_dirtakes a file/subdirectory path and returns a Path::Extended::File object if it doesn't point to an existing directory (if it does point to a directory, it returns a Path::Extended::Dir object). This is handy if you don't know a path is a file or a directory. You can tell which is the case by calling ->is_dir method (if it's a file, ->is_dir returns false, otherwise true).dir_or_filedoes the same above but Path::Extended::Dir has precedence.recursedir('path/to/somewhere')->recurse( callback => sub { my $file_or_dir = shift; ... }); takes a hash and iterates through the directory and all its subdirectories recursively, and call the callback function for each entry. Options are:
subsumes, containsreturns if the path belongs to the object, or vice versa. See Path::Class::Dir for details.volumereturns a volume of the path (if any).AUTHORKenichi Ishigaki, <ishigaki@cpan.org>COPYRIGHT AND LICENSECopyright (C) 2008 by Kenichi Ishigaki.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |