Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: File Properties/attributes in Win32

by BrowserUk (Pope)
on Mar 14, 2006 at 11:57 UTC ( #536537=note: print w/ replies, xml ) Need Help??


in reply to Re: File Properties/attributes in Win32
in thread File Properties/attributes in Win32

# HIDDEN and other attributes are exported by Win32::File by default

Did you try that? If so, perhaps you could explain what I'm doing wrong here?

#! perl -slw use strict; use Win32::File qw[ GetAttributes ]; while( my $file = glob $ARGV[0] ) { GetAttributes( $file, my $attrs ); printf "%1s%1s%1s%1s%1s%1s%1s%1s%1s %s\n", ( $attrs & ARCHIVE ) ? 'A' : ' ', ( $attrs & COMPRESSED) ? 'C' : ' ', ( $attrs & DIRECTORY ) ? 'D' : ' ', ( $attrs & HIDDEN ) ? 'H' : ' ', ( $attrs & NORMAL ) ? 'N' : ' ', ( $attrs & OFFLINE ) ? 'O' : ' ', ( $attrs & READONLY ) ? 'R' : ' ', ( $attrs & SYSTEM ) ? 'S' : ' ', ( $attrs & TEMPORARY ) ? 'T' : ' ', $file; } __END__ C:\test>junk4 *.pl Bareword "ARCHIVE" not allowed while "strict subs" in use at C:\test\j +unk4.pl line 7. Bareword "COMPRESSED" not allowed while "strict subs" in use at C:\tes +t\junk4.pl line 7. Bareword "DIRECTORY" not allowed while "strict subs" in use at C:\test +\junk4.pl line 7. Bareword "HIDDEN" not allowed while "strict subs" in use at C:\test\ju +nk4.pl line 7. Bareword "NORMAL" not allowed while "strict subs" in use at C:\test\ju +nk4.pl line 7. Bareword "OFFLINE" not allowed while "strict subs" in use at C:\test\j +unk4.pl line 7. Bareword "READONLY" not allowed while "strict subs" in use at C:\test\ +junk4.pl line 7. Bareword "SYSTEM" not allowed while "strict subs" in use at C:\test\ju +nk4.pl line 7. Bareword "TEMPORARY" not allowed while "strict subs" in use at C:\test +\junk4.pl line 7. Execution of C:\test\junk4.pl aborted due to compilation errors.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^2: File Properties/attributes in Win32
Download Code
Re^3: File Properties/attributes in Win32
by rafl (Friar) on Mar 14, 2006 at 12:05 UTC

    I didn't actually try it as I don't own a Win32 box, but the source code tells me that.

    Exporter doesn't seem to import the symbols in @EXPORT if you specify a list of symbols yourself. You can either not import the GetAttributes function, import all attributes yourself or use the attributes with their full name.

    I also think you could bug the author of the module to create an export tag that allows you to import all attributes at once.

    Flo

      This is one of several of the Win32::* 'standard' modules I've encountered that have a pretty peculiar way of exporting constants.

      In this case, they don't export the two quite specifically named functions into your namespace, but do export a dozen or so constants with very general names. But if you choose to import the function(s) you wish to use, the constants don't get exported!

      That leaves you either fully qualifying them (as functions) or importing them manually, or using the functions fully qualified and having this random set of constants scribbled over your namespace!

      To recap, you can do this:

      #! perl -slw use strict; use Win32::File qw[ GetAttributes ]; while( my $file = glob $ARGV[0] ) { GetAttributes( $file, my $attrs ); printf "%1s%1s%1s%1s%1s%1s%1s%1s%1s %s\n", ( $attrs & Win32::File::ARCHIVE() ) ? 'A' : ' ', ( $attrs & Win32::File::COMPRESSED()) ? 'C' : ' ', ( $attrs & Win32::File::DIRECTORY() ) ? 'D' : ' ', ( $attrs & Win32::File::HIDDEN() ) ? 'H' : ' ', ( $attrs & Win32::File::NORMAL() ) ? 'N' : ' ', ( $attrs & Win32::File::OFFLINE() ) ? 'O' : ' ', ( $attrs & Win32::File::READONLY() ) ? 'R' : ' ', ( $attrs & Win32::File::SYSTEM() ) ? 'S' : ' ', ( $attrs & Win32::File::TEMPORARY() ) ? 'T' : ' ', $file; }

      Or this:

      #! perl -slw use strict; use Win32::File; while( my $file = glob $ARGV[0] ) { Win32::File::GetAttributes( $file, my $attrs ); printf "%1s%1s%1s%1s%1s%1s%1s%1s%1s %s\n", ( $attrs & ARCHIVE ) ? 'A' : ' ', ( $attrs & COMPRESSED) ? 'C' : ' ', ( $attrs & DIRECTORY ) ? 'D' : ' ', ( $attrs & HIDDEN ) ? 'H' : ' ', ( $attrs & NORMAL ) ? 'N' : ' ', ( $attrs & OFFLINE ) ? 'O' : ' ', ( $attrs & READONLY ) ? 'R' : ' ', ( $attrs & SYSTEM ) ? 'S' : ' ', ( $attrs & TEMPORARY ) ? 'T' : ' ', $file; }

      Or this:

      #! perl -slw use strict; use Win32::File qw[ GetAttributes ARCHIVE COMPRESSED DIRECTORY HIDDEN NORMAL OFFLINE READONLY SYSTEM TEMPORARY ]; while( my $file = glob $ARGV[0] ) { GetAttributes( $file, my $attrs ); printf "%1s%1s%1s%1s%1s%1s%1s%1s%1s %s\n", ( $attrs & ARCHIVE ) ? 'A' : ' ', ( $attrs & COMPRESSED) ? 'C' : ' ', ( $attrs & DIRECTORY ) ? 'D' : ' ', ( $attrs & HIDDEN ) ? 'H' : ' ', ( $attrs & NORMAL ) ? 'N' : ' ', ( $attrs & OFFLINE ) ? 'O' : ' ', ( $attrs & READONLY ) ? 'R' : ' ', ( $attrs & SYSTEM ) ? 'S' : ' ', ( $attrs & TEMPORARY ) ? 'T' : ' ', $file; }

      Or this:

      #! perl -slw use strict; use Win32::File (); while( my $file = glob $ARGV[0] ) { Win32::File::GetAttributes( $file, my $attrs ); printf "%1s%1s%1s%1s%1s%1s%1s%1s%1s %s\n", ( $attrs & Win32::File::ARCHIVE() ) ? 'A' : ' ', ( $attrs & Win32::File::COMPRESSED()) ? 'C' : ' ', ( $attrs & Win32::File::DIRECTORY() ) ? 'D' : ' ', ( $attrs & Win32::File::HIDDEN() ) ? 'H' : ' ', ( $attrs & Win32::File::NORMAL() ) ? 'N' : ' ', ( $attrs & Win32::File::OFFLINE() ) ? 'O' : ' ', ( $attrs & Win32::File::READONLY() ) ? 'R' : ' ', ( $attrs & Win32::File::SYSTEM() ) ? 'S' : ' ', ( $attrs & Win32::File::TEMPORARY() ) ? 'T' : ' ', $file; }

      None of which seem particularly satisfactory from either a 'quick script-DWIM' or a software engineering point of view.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Here's another radical idea :)
        use Win32::File; use Win32::File qw[ GetAttributes ];
        But I agree, the constants should have their own tag.

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://536537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (17)
As of 2014-04-23 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (552 votes), past polls