
mary.vanderbuild1.5524942607229475E12 asked a question.
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
no idea? :confused:
mary
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
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;
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
thanks for your brief example - obviously i didn't read any further last week. :o
It does exactly what i want!
thanks again :rolleyes:
mary
i don't have to load and unload kernel32.dll, right?!
mary
... 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.