Path::Util

decompose file path

pathutil

Path::Util

Break up a file path into its components.

Usage:

use Path::Util;

my $p = Path::Util.new("d:\docs\usage.txt"); It can break-up Unix like or Dos like file paths.

say p.drive; # it gets the drive letter, for Windwos only. Otherwise, it returns "". say p.directory; or say p.getext; or say p.getbasename; # returns the filename without directory say $p.getjustname; # returns the filename without directory and extension

Above also work without get.

say $p.print; # prints all components

say $p.separator; # returns the separator found in the path, it can be "" or "/" or "".

say $p.fsseparator; # returns Windows or Unix-like file separator depending where you run your script

say $p.getnumberofdirlevel; # number of levels in the directory

say $p.getdirlevel(2); # returns directory up to the second level

say $p.tocygwin(); # returns the cygwin format of a Windows path, nothing happens if it is of other kind. e.g. /cygdrive/d/music/after.mp4

say $p.tomsys(); # returns the msysformat of a Windows path, nothing happens if it is of other kind. e.g. /d/music/after.mp4

Also, it is possible to use them non-object oriented way.

say Path::Util.getbasename("d:\docs\usage.txt");

Extension is returned without dot. Directories are returned without ending separator.

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.