in reply to -d on windows

readdir returns a list of names, not of fully qualified paths. You can see that by printing out $_ and comparing that against "e:\\core\\ops_utilities\\$_". Only the latter will be what you expect.

Whenever you find things from a grep not returning what you think, it helps to modify the grep to tell you what it does:

my @files = grep { warn "Checking '$_' for -d:" . -d $_; !-d $_} readd +ir(DIR);

Replies are listed 'Best First'.
Re^2: -d on windows
by Scarborough (Hermit) on Mar 27, 2008 at 13:46 UTC
    Thanks for the reminder, it all came flooding back as soon as I read the first line.
    Code changed too
    my $dir = "e:\\core\\ops_utilities\\"; opendir DIR, $dir or die $!; my @files = grep {!-d $dir.$_} readdir(DIR);
    And all works as expected. Thank you
      Here's a variation that doesn't require an unusual trailing backslash, gives a better error message, and avoids using global variables:
      use File::Spec::Functions qw( catfile ); my $dir = "e:\\core\\ops_utilities"; opendir(my $dh, $dir) or die("Unable to read utilities directory \"$dir\": $!\n"); my @files = grep { !-d catfile($dir, $_) } readdir($dh);

      The following might be more useful:

      my @files = grep { !-d } map { catdir($dir, $_) } readdir($dh);