Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Hidden file attribute in Win32

by bitman (Scribe)
on May 21, 2002 at 16:46 UTC ( #168187=perlquestion: print w/replies, xml ) Need Help??
bitman has asked for the wisdom of the Perl Monks concerning the following question:

Is there any 'nice' way to check if a file is hidden in windows without THIS :-

my $hideflag=`attrib $src`; if ( $hideflag=~m/^ H/ ) {

stat & file test operators seem to not have anything to offer.

Title edit by tye (was "Hide well Frodo")

Replies are listed 'Best First'.
Re: Hidden file attribute in Win32 (was: Hide well Frodo)
by VSarkiss (Monsignor) on May 21, 2002 at 17:14 UTC

    You can use the Win32::File module, which is a little simpler than Win32API::File, like so:

    use Win32::File qw(GetAttributes HIDDEN); my $attr; if (GetAttributes($src, $attr)) { if ($attr & HIDDEN) { # whatever.... } } else { warn "Error getting attributes of $src"; }
    I don't do a lot of Win32 programming but just happened to know this one because I had to do something similar a while ago....

    Added code to check return value of GetAttributes. Shame on me for forgetting. Forty Hail Larrys.

Re: Hidden file attribute in Win32 (was Hide well Frodo)
by particle (Vicar) on May 21, 2002 at 17:03 UTC
    use Win32API::File;
    i think GetHandleInformation is the method, and FILE_ATTRIBUTE_HIDDEN is the flag you'll want. sorry i don't have a complete example for you.

    ~Particle *accelerates*

Re: Hidden file attribute in Win32
by marinersk (Priest) on Jul 09, 2016 at 04:45 UTC

    Just to expand a bit on the answers given:

    #!/usr/bin/perl use strict; use Win32::File; my $hidfnm = 'hideme.txt'; my $getatr = 0; my $getret = &Win32::File::GetAttributes($hidfnm, $getatr); if ($getret) { if ($getatr & HIDDEN) { print "File is hidden. Unhiding\n"; } else { print "File is not hidden. Hiding\n"; } # Toggle the HIDDEN flag my $setatr = ($getatr ^ HIDDEN); my $setret = &Win32::File::SetAttributes($hidfnm, $setatr); } __END__


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://168187]
Approved by VSarkiss
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2018-04-22 05:03 GMT
Find Nodes?
    Voting Booth?