Solved

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

Posted on 1998-06-28
8
546 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

10 Experts available now in Live!

Get 1:1 Help Now