Find Windows Compression attribute?

N

NovasTaylor

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
 
Q

QoS

NovasTaylor said:
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
 
S

smallpond

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
 
N

NovasTaylor

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
 
N

NovasTaylor

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
 
N

NovasTaylor

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top