Solved

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

Posted on 1998-06-28
8
549 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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