Solved

How do I compress a file (under NT4)???

Posted on 1998-06-28
8
547 Views
Last Modified: 2008-02-01
As I understand it the following code should compress a file using the standard NT file compression, but it does not work.  Any ideas???

Also does anyone know which unit I need to get the value for FSCTL_SET_COMPRESSION - I write a small C program to display this constant to get its value as it did not seem to be defined in the Windows stuff.

I have removed the error processing to minimise the code I need to post.

Regards

Dave

procedure FCompress(pathname: string);
const
   comp_buflen = 16384;       // 16K buffer

var
   TFifile:          TFileStream;
   comp_buffer:      Pchar;
   comp_result:      Boolean;
   BytesReturned:    LongInt;

begin
    comp_buffer := nil;

    GetMem(comp_buffer, comp_buflen);

    TFIfile := TFileStream.create(pathname,
               fmOpenReadWrite and fmShareDenyWrite);

    comp_result := deviceIOControl(TFifile.Handle,
       $09c040, // This should be FSCTL_SET_COMPRESSION,
                // but this constant seems to have been
               // omitted from the Delphi libraries
       comp_buffer,
       comp_buflen,
       nil,
       0,
       BytesReturned,
       nil);

    TFIfile.Free;
    FreeMem(comp_buffer);
    comp_buffer := nil;

end;
0
Comment
Question by:cdms
8 Comments
 
LVL 1

Expert Comment

by:rene_moeller
ID: 1356170
why not use this component with source code found at DSP: http://sunsite.icm.edu.pl/delphi/ftp/d10free/tlzrw1.zip

Guess it should do the job


0
 

Author Comment

by:cdms
ID: 1356171
Sorry, but a component is overkill for this purpose, and does answer the main point of my question - where have I gone wrong???

0
 

Author Comment

by:cdms
ID: 1356172
Having looked at the component Rene suggested, I note that this ia a component to compress a file into an archive.  Just to clarify, this is NOT what I want.

All I want to be able to do is turn on the NTFS compression attribute, compressing the file in situ.

Hope this helps...

Dave
0
 
LVL 1

Expert Comment

by:pjdb
ID: 1356173
In the FindFirst, the attribute value for the compressed files is 2048 ($800). However, Microsoft say it's 128 ($80)..... (i've never obtain this value).

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:cdms
ID: 1356174
I dont want to find the compressed files.  I want to compress them!!!

However, I found the answer elsewhere.  The code should read...

procedure FCompress(pathname: string);
const
   comp_buflen = sizeof(Integer);
var
   TFifile:          TFileStream;
   comp_buffer:      Integer;
   comp_result:      Boolean;
   BytesReturned:    LongInt;

begin
    comp_buffer := 1; // NT default compression

    TFIfile := TFileStream.create(pathname,
               fmOpenReadWrite and fmShareDenyWrite);

    comp_result := deviceIOControl(TFifile.Handle,
       $09c040, // This should be FSCTL_SET_COMPRESSION,
                // but this constant seems to have been
                // omitted from the Delphi libraries
       Pointer(@comp_buffer),
       comp_buflen,
       nil,
       0,
       BytesReturned,
       nil);

    TFIfile.Free;
end;

0
 
LVL 1

Expert Comment

by:pjdb
ID: 1356175
I have understand what you mean, but have you try the value 2048 and 128 for FSCTL_SET_COMPRESSION? You should know that Microsoft use different names for the same values depending on where they are. That's why i'gave you the corresponding values for another function.
0
 

Author Comment

by:cdms
ID: 1356176
This value is actually very specific, and is a bit-mapped value with four different components. The value of 9c040 (hex) is correct.
0
 
LVL 7

Accepted Solution

by:
linda101698 earned 100 total points
ID: 1356177
I am posting the solution found by cdms so the solution can be saved in the previously asked question.

Linda Gardner
Customer Service @ Experts Exchange

Solution:
I found the answer elsewhere.  The code should read...

     procedure FCompress(pathname: string);
     const
        comp_buflen = sizeof(Integer);
     var
        TFifile:          TFileStream;
        comp_buffer:      Integer;
        comp_result:      Boolean;
        BytesReturned:    LongInt;

     begin
         comp_buffer := 1; // NT default compression

         TFIfile := TFileStream.create(pathname,
                    fmOpenReadWrite and fmShareDenyWrite);

         comp_result := deviceIOControl(TFifile.Handle,
            $09c040, // This should be FSCTL_SET_COMPRESSION,
                     // but this constant seems to have been
                     // omitted from the Delphi libraries
            Pointer(@comp_buffer),
            comp_buflen,
            nil,
            0,
            BytesReturned,
            nil);

         TFIfile.Free;
     end;






0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 107
drawing animated level bar based on numbers 3 88
TServerSocket - file via sendbuf or Text via sendtext ? 1 43
Find and Replace Stream with 0s 8 57
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now