in reply to filtering hidden files on Win32

Same basic code... just a few tweaks here and there to get the constant working.

#!perl -w use strict; use Cwd; use Win32::File; my $attribs; my $dir = cwd(); print $dir,$/; opendir( DIR, $dir ) or die "Couldn't open $main::DIR: $!\n"; my @vis_files = grep { -f $dir.'/'.$_ and Win32::File::GetAttributes($_, $attribs) and !($attribs & HIDDEN) } readdir(DIR); closedir( DIR ) or warn "Couldn't close $main::DIR: $!\n"; print $_, $/ for @vis_files;

Replies are listed 'Best First'.
Re: Answer: filtering hidden files on Win32
by anonymized user 468275 (Curate) on Jan 14, 2016 at 13:36 UTC
    When writing a fire-and-forget duplicates finder just now, I found this thread very useful. My coding style and approach seems rather different though. But whether low code granularity is good is often a highly debated issue.
    sub dfind { my ($dref, $top) = @_; hidden( $top ) and return; if (-d $top) { for my $file (glob( "$top/*" )) { dfind( $dref, $file ); } } else { register( $dref, $top ); # add to HoA } } sub hidden { my $file = shift; my $attribs; Win32::File::GetAttributes($file, $attribs); return $attribs & HIDDEN; }
    Update: note that hidden directories and files are both filtered out owing to how the recursion is contructed.