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__

Results:

D:\PerlMonks>hide1 D:\PerlMonks>echo>hideme.txt This is a test. D:\PerlMonks>dir Volume in drive S is SteveData Volume Serial Number is 78B4-33A0 Directory of D:\PerlMonks 07/09/2016 12:38 AM <DIR> . 07/09/2016 12:38 AM <DIR> .. 07/09/2016 12:38 AM 88 hide1.bat 07/09/2016 12:41 AM 448 hide1.pl 07/09/2016 12:41 AM 17 hideme.txt 3 File(s) 553 bytes 2 Dir(s) 29,695,066,112 bytes free D:\PerlMonks>perl hide1.pl File is not hidden. Hiding D:\PerlMonks>dir Volume in drive S is SteveData Volume Serial Number is 78B4-33A0 Directory of D:\PerlMonks 07/09/2016 12:38 AM <DIR> . 07/09/2016 12:38 AM <DIR> .. 07/09/2016 12:38 AM 88 hide1.bat 07/09/2016 12:41 AM 448 hide1.pl 2 File(s) 536 bytes 2 Dir(s) 29,695,066,112 bytes free D:\PerlMonks>perl hide1.pl File is hidden. Unhiding D:\PerlMonks>dir Volume in drive S is SteveData Volume Serial Number is 78B4-33A0 Directory of D:\PerlMonks 07/09/2016 12:38 AM <DIR> . 07/09/2016 12:38 AM <DIR> .. 07/09/2016 12:38 AM 88 hide1.bat 07/09/2016 12:41 AM 448 hide1.pl 07/09/2016 12:41 AM 17 hideme.txt 3 File(s) 553 bytes 2 Dir(s) 29,695,066,112 bytes free D:\PerlMonks>


In reply to Re: Hidden file attribute in Win32 by marinersk
in thread Hidden file attribute in Win32 by bitman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.