Find Windows Compression attribute?

Discussion in 'Perl Misc' started by NovasTaylor, Mar 5, 2009.

  1. NovasTaylor

    NovasTaylor Guest

    Hi folks,

    Is there a way I can identify the windows compression property
    "Compress contents to save disk space" on files and folders? I have a
    large directory structure where I need to find files that have the
    compression property active and ideally turn that attribute off.
    Simply identifying the files with that attribute would be a good first
    step.

    Thanks!

    Tim
     
    NovasTaylor, Mar 5, 2009
    #1
    1. Advertising

  2. NovasTaylor

    Guest

    NovasTaylor <> wrote in message-id: <>

    >
    > Hi folks,
    >
    > Is there a way I can identify the windows compression property
    > "Compress contents to save disk space" on files and folders? I have a
    > large directory structure where I need to find files that have the
    > compression property active and ideally turn that attribute off.
    > Simply identifying the files with that attribute would be a good first
    > step.
    >
    > Thanks!
    >
    > Tim


    parse the output of compact /s
    the third column of the output displays the compression ratio.

    example output: 63344 : 63344 = 1.0 to 1 CDILLA05.DLL
     
    , Mar 5, 2009
    #2
    1. Advertising

  3. NovasTaylor

    smallpond Guest

    On Mar 5, 8:43 am, NovasTaylor <> wrote:
    > Hi folks,
    >
    > Is there a way I can identify the windows compression property
    > "Compress contents to save disk space" on files and folders? I have a
    > large directory structure where I need to find files that have the
    > compression property active and ideally turn that attribute off.
    > Simply identifying the files with that attribute would be a good first
    > step.
    >
    > Thanks!
    >
    > Tim


    I believe that you can get this from Win32::File
     
    smallpond, Mar 5, 2009
    #3
  4. NovasTaylor

    NovasTaylor Guest

    I can retrieve the compression attribute successfully with
    Win32::File, but I can not set it. Any ideas why? I can set the
    attribute using Windows Explorer. In the following code I successfully
    detect that my test file is not compressed. THe "File is not
    compressed..." line prints out and I get no error from teh
    SetAttributes command, yet the file remains not compressed.

    use strict;
    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\n";
    }
    else
    {
    print "File is not compressed. I will compress it!!\n"; # this
    line prints!
    Win32::File::SetAttributes($path, COMPRESSED ) or die "Can not set
    to COMPRESSED: $!";
    }


    Any help would be greatly appreciated.
    Cheers,

    Tim

    On Mar 5, 11:12 am, smallpond <> wrote:
    > On Mar 5, 8:43 am, NovasTaylor <> wrote:
    >


    > > Hi folks,

    >
    > > Is there a way I can identify the windows compression property
    > > "Compress contents to save disk space" on files and folders? I have a
    > > large directory structure where I need to find files that have the
    > > compression property active and ideally turn that attribute off.
    > > Simply identifying the files with that attribute would be a good first
    > > step.

    >
    > > Thanks!

    >
    > > Tim

    >
    > I believe that you can get this from Win32::File
     
    NovasTaylor, Mar 5, 2009
    #4
  5. NovasTaylor

    NovasTaylor Guest

    oh, and this also does not work:

    Win32::File::SetAttributes($path, $attr| COMPRESSED) or die "Can not
    set to COMPRESSED: $!";

    What am I missing?

    Tim
     
    NovasTaylor, Mar 5, 2009
    #5
  6. NovasTaylor

    NovasTaylor Guest

    I have my answer, as provided over at perlmonks.org.

    You can detect compression using GetAttributes but can not remove it
    using SetAttributes. To remove compression I am using the system
    command:
    compact /u
    and
    compact /u /i /s

    I hope that helps someone out there, some day...

    Cheers,

    Tim


    On Mar 5, 3:43 pm, NovasTaylor <> wrote:
    > oh, and this also does not work:
    >
    > Win32::File::SetAttributes($path, $attr| COMPRESSED) or die "Can not
    > set to COMPRESSED: $!";
    >
    > What am I missing?
    >
    > Tim
     
    NovasTaylor, Mar 6, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bostonasian
    Replies:
    1
    Views:
    838
    Joris Gillis
    Sep 18, 2005
  2. A. Bonslater
    Replies:
    0
    Views:
    357
    A. Bonslater
    Sep 5, 2008
  3. Wybo Dekker
    Replies:
    1
    Views:
    399
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    440
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    870
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page