cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mary_v
Level 6

Windows file compression

How am i able to detect if a file is compressed via windows file compression?

I know there exists an attribute on ntfs file systems but am not able to retrieve this piece of information via GetFileInfo in custom actions.

Any ideas how to achieve this?
mary
Labels (1)
0 Kudos
(10) Replies
mary_v
Level 6

... hm maybe call a dll ? ...
no idea? :confused:

mary
0 Kudos
mary_v
Level 6

nobody a solution - I am sure not the only one with this problem, right? 🙂
0 Kudos
MrTree
Level 6

why do you want to detect if the file is compressed, just uncompress it every time with compact /U /S /I "C:\file.txt"
0 Kudos
mary_v
Level 6

well - usually i want to execute functions only if necessary...

my situation is as follows:
while updating sql databases (alter tables etc), sometimes they are compressed and my updates fails - i want to check actually BEFORE updating wether the databases are compressed.

then i would have to stop the sql server which maybe shuts down other apps ...

mary
0 Kudos
MrTree
Level 6

sure this is not sexy, but I don't know an IS function that shows you the status of the file.

The comapct.exe included in Windows works fine for such operations, it doesn't create errors if the file is not compacted.

LaunchAppAndWait(WINSYSDIR ^ "compact.exe", "/U /I "+TARGETDIR ^ "SQLDB.MDF", WAIT|LAAW_OPTION_HIDDEN);

helps me to prevent errors with compacted SQL DBs.

If you have to check the file status before you use compact.exe you may be use a Windows dll function.

Like this:
------------------------------------------------------------------------------
prototype int Kernel32.GetFileAttributes(string);
export prototype BOOL IsFileCompressed(string);

function BOOL IsFileCompressed(filename)
int attributes, nResult;
begin
nResult = UseDLL(WINSYSDIR ^ "Kernel32.dll");

if(nResult != 0) then
MessageBox("Unable to load " + WINSYSDIR ^ "Kernel32.dll.", SEVERE);
exit;
endif;

attributes = GetFileAttributes(filename);
UnUseDLL(WINSYSDIR ^ "Kernel32.dll");
return (attributes & 0x800) == 0x800;
end;
------------------------------------------------------------------------------

and call:

if(IsFileCompressed("C:\\Temp\\test.txt")) then
//decompress file
endif;
0 Kudos
mary_v
Level 6

thanks for your reply - my approach is quite similar

as a workaround i also thought about using compact in combination with findstr to get the result in only one line and then parse this line to extract the number of compressed files.

but i would do this only if i can't use the GetFileAttributeEx function in kernel32.dll

Any idea how to call it or should i try your little example first?

i must confess - i'll give it a try after the weekend 😉

mary
0 Kudos
mary_v
Level 6

@MrTree:

thanks for your brief example - obviously i didn't read any further last week. 😮

It does exactly what i want!

thanks again :rolleyes:
mary
0 Kudos
mary_v
Level 6

... just to make everything right:

i don't have to load and unload kernel32.dll, right?!

mary
0 Kudos
MrTree
Level 6

mary_v wrote:
... just to make everything right:

i don't have to load and unload kernel32.dll, right?!

mary


that's right, cause every Windows Programm even InstallShield needs/loads kernel32.dll.
0 Kudos
RobertDickau
Flexera Alumni

Right, the UseDLL help topic mentions not needing to load and unload that and other system DLLs.
0 Kudos