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

Hi monks!

Is there a file test for DOS perl that will tell me if a file has the hidden attribute set?

Replies are listed 'Best First'.
Re: how to tell if file is hidden
by almut (Canon) on Jul 29, 2008 at 17:39 UTC
Re: how to tell if file is hidden
by Bloodnok (Vicar) on Jul 29, 2008 at 17:41 UTC
    perldoc Win32::File

    Untested (access to a Windoze box is a problem at the moment - mines' just BSoDd:-((, but something like this should suffice...

    use Win32::File qw/GetAttributes/; my $attrs; GetAttributes("some_file", \$attrs); if ($attrs | HIDDEN) { . . .

    HTH ,

    Update Wouldn't appear to be my day today - thanx to almut who has pointed out the error of my ways - for
    if ($attrs | HIDDEN) {,
    read if ($attrs & HIDDEN) {

    At last, a user level that overstates my experience :-))
      if ($attrs | HIDDEN) {

      I think that should rather be  if ($attrs & HIDDEN) {...}.

      Update: Also, I suppose if you request GetAttributes to be exported, you'll also need to specify HIDDEN, i.e.

      use Win32::File qw/GetAttributes HIDDEN/;

      Or just import :DEFAULT, too:

      use Win32::File qw/GetAttributes :DEFAULT/;

      Alternatively, simply use Win32::File; and then say fully qualified Win32::File::GetAttributes(...), in which case the HIDDEN constant will not be kept from being exported by default.

      (IOW, specifying anything in the import list of a module will deactivate the default export list (@EXPORT) — so in that case you have to explicitly specify everything you need, or include the :DEFAULT tag, representing everything in @EXPORT.)