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>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|