Skip to content

Instantly share code, notes, and snippets.

@ugexe
Last active March 7, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugexe/327349da6cd1c5a6d5c3 to your computer and use it in GitHub Desktop.
Save ugexe/327349da6cd1c5a6d5c3 to your computer and use it in GitHub Desktop.
method dir(IO::Path:D:
Mu :$test = $*SPEC.curupdir,
:$absolute,
:$Str,
:$CWD = $*CWD,
) {
CATCH { default {
fail X::IO::Dir.new(
:path(nqp::box_s($.abspath,Str)), :os-error(.Str) );
} }
my $cwd_chars = $CWD.chars;
my str $cwd = nqp::cwd();
nqp::chdir(nqp::unbox_s($.abspath));
my $abspath-sep := $.abspath eq $!SPEC.dir-sep
?? $!SPEC.dir-sep
!! $.abspath ~ $!SPEC.dir-sep;
my Mu $dirh := nqp::opendir(nqp::unbox_s($.abspath));
gather {
loop {
my str $str_elem = nqp::nextfiledir($dirh);
if nqp::isnull_s($str_elem) || nqp::chars($str_elem) == 0 {
nqp::closedir($dirh);
last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment