Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

Is there any module to get the hidden files in a particular directory (windows), if so please give your suggestions.

Replies are listed 'Best First'.
Re: Retrive Hidden files
by sh1tn (Priest) on Jun 04, 2005 at 11:37 UTC
    Both readdir and glob return files with 'hidden' attribute set:
    perl -e "opendir DH, '\hidden' or die $!;print $_,$/ while $_ = readdi +r DH" . .. hidden.txt perl -e "print $_,$/ for glob '\Hidden\*'" \Hidden\hidden.txt


Re: Retrive Hidden files
by wfsp (Abbot) on Jun 04, 2005 at 11:04 UTC
    This may help:
    #!/usr/bin/perl use strict; use warnings; use Win32::File; my $file = 'some.file'; my $attr; Win32::File::GetAttributes($file, $attr); if ($attr & (Win32::File::HIDDEN)){ print "$file is hidden\n"; } else{ print "$file not hidden\n"; }
      He means to list the hidden files, such as with readdir or glob. I doubt if these include hidden files, but I doubt it.

      Well, if all else fails, it's still possible to get a directory listing with plain API calls (FindFirstFile, FindNextFile, and FileClose) and Win32::API. I'm not sure there's another Win32 specific module that offers a simpler interface.

        readdir does return hidden files.

        Something like this could identify them:

        #!/usr/bin/perl use strict; use warnings; use Win32::File; my $dir = 'some.dir'; opendir(my $dh, $dir); my @files = readdir $dh; for my $file (@files){ my $attr; Win32::File::GetAttributes($file, $attr); if ($attr & (Win32::File::HIDDEN)){ print "$file is hidden\n"; } else{ print "$file not hidden\n"; } }

        Update:

        activestate 5.8.6 on winXP home

Re: Retrive Hidden files
by ambrus (Abbot) on Jun 05, 2005 at 08:40 UTC

    Anf if you don't want perl, then just do dir /a