Solved

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

Posted on 1998-06-28
8
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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