Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-06-28
8
Medium Priority
?
558 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
Technology Partners: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

636 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