in reply to Re: How to remove COMPRESSED attribute with Win32::File?
in thread How to remove COMPRESSED attribute with Win32::File?

Thank you for the replies. I tried the following without success:
use Win32::File; my $path="C:\\temp\\Perl\\TestFolder\\TestFile.txt"; my $attr; Win32::File::GetAttributes($path, $attr); if ($attr & COMPRESSED) { print "File is compressed. Now uncompress it!\n"; $attr &= ~COMPRESSED; Win32::File::SetAttributes($path, $attr); } else { print "File is not compressed. Nothing to do here.\n"; }
Any ideas on what I am doing wrong? I can set and unset the attribute in Windows Explorer but with the Perl code compression remains on. Cheers, Tim

Replies are listed 'Best First'.
Re^3: How to remove COMPRESSED attribute with Win32::File?
by ikegami (Patriarch) on Mar 06, 2009 at 04:18 UTC

    My first thought was:

    Maybe if you checked for errors, you'd know? The docs state how to detect if an error occured. And when one does, you can probably find out the error from $^E.

    But it seems SetFileAttributes, the system call for which Win32::File::SetAttributes is a wrapper, simply ignores the flag.

    The documentation directs programmers to "use the DeviceIoControl function with the FSCTL_SET_COMPRESSION operation."

Re^3: How to remove COMPRESSED attribute with Win32::File?
by syphilis (Archbishop) on Mar 06, 2009 at 04:49 UTC
    Any ideas on what I am doing wrong?

    I don't think you can change the 'COMPRESSED' status of a file using Win32::File. The MSDN documentation I'm looking at says that SetFileAttributes (which is what Win32::File is using) is unable to set the compression attribute - and I suspect that it is likewise unable to turn that attribute off. At least, I can't get the script that you posted to do the right thing, either - and it's not throwing any errors.

    Cheers,
    Rob