The catpath routine

Combined from primary sources listed below.

In class IO::Spec::Unix ( Type/IO/Spec/Unix )§

See primary docmentation in context for method catpath.

method catpath§

method catpath ($, Str:D $part1, Str:D $part2 --> Str:D)

Takes two path fragments and concatenates them, adding or removing a path separator, if necessary. The first argument is ignored (it exists to maintain consistent interface with other IO::Spec types for systems that have volumes).

IO::Spec::Unix.catpath($, 'some/dir', 'and/more').say;
# OUTPUT: «some/dir/and/more␤»

In class IO::Spec::Win32 ( Type/IO/Spec/Win32 )§

See primary docmentation in context for method catpath.

method catpath§

method catpath (Str:D $volume, Str:D $dir, Str:D $file --> Str:D)

Concatenates a path from given volume, a chain of directories, and file. An empty string can be given for any of the three arguments. No attempt to make the path canonical is made. Use canonpath for that purpose.

IO::Spec::Win32.catpath('C:', '/some/dir', 'foo.txt').say;
# OUTPUT: «C:/some/dir\foo.txt␤»

IO::Spec::Win32.catpath('C:', '/some/dir', '').say;
# OUTPUT: «C:/some/dir␤»

IO::Spec::Win32.catpath('', '/some/dir', 'foo.txt').say;
# OUTPUT: «/some/dir\foo.txt␤»

IO::Spec::Win32.catpath('E:', '', 'foo.txt').say;
# OUTPUT: «E:foo.txt␤»

In class IO::Spec::Cygwin ( Type/IO/Spec/Cygwin )§

See primary docmentation in context for method catpath.

method catpath§

method catpath (Str:D $volume, Str:D $dir, Str:D $file --> Str:D)

Same as IO::Spec::Win32.catpath, except will also change all backslashes to slashes at the end:

IO::Spec::Cygwin.catpath('C:', '/some/dir', 'foo.txt').say;
# OUTPUT: «C:/some/dir/foo.txt␤»

IO::Spec::Cygwin.catpath('C:', '/some/dir', '').say;
# OUTPUT: «C:/some/dir␤»

IO::Spec::Cygwin.catpath('', '/some/dir', 'foo.txt').say;
# OUTPUT: «/some/dir/foo.txt␤»

IO::Spec::Cygwin.catpath('E:', '', 'foo.txt').say;
# OUTPUT: «E:foo.txt␤»