Solved

extract files

Posted on 2000-04-07
7
377 Views
Last Modified: 2010-04-04
how to extract files from program or how to copy files from program to directory?
0
Comment
Question by:Jurica2505
[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
7 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2694621
Do you mean reasources that you have compiled into your exe? If so you would want to checkout TReasourceStream

GL
mike
0
 
LVL 5

Expert Comment

by:Gwena
ID: 2694712
listening
0
 
LVL 5

Expert Comment

by:Gwena
ID: 2694715
listening
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:umulig
ID: 2695082
Take a look at this link
http://www.gnomehome.demon.nl/uddf/pages/resource.htm

Regards
Umulig
0
 
LVL 4

Expert Comment

by:Radler
ID: 2702151
Hi Jurica,

There is a our pending at
http://www1.experts-exchange.com/Computers/Programming/Windows/Delphi/Q_10322797.html

Your trouble has better easy solution if you have Delhi 4 or above

#
At the menu Project->Resources open the Project resources.
RightClick the mouse and add a new type "RT_RCDATA"
After this select the file to incorporate inside you application.
You can repeat this to other file, the default name is RT_RCDATA_1.

Put the follow code to extract the resource file


function TMainFrm.XtractRes( DestFile : string ) : boolean;
var
  ZipRes : TResourceStream;
begin
  Result:=False;
  try
    ZipRes:=TResourceStream.Create( System.MainInstance, 'RT_RCDATA_1',                   'RT_RCDATA');
      try
                  ZipRes.SaveToFile( DestFile );
                except
        on E : exception do begin
              DeleteFile( DestFile );
              MessageDlg( 'I get the error: '#13 + E.Message, mtError, [mbOK], 0);
      end;
      end;
      ZipRes.Free;
      except
                     Result:=False;
                     Exit;
      end;
       Result:=True;
end;

T++, Radler.
0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 2731089
If you are looking at integrating a Zip/Unzip functionality in to your Delphi app, try:

www.ziptv.com
0
 

Accepted Solution

by:
peteraa earned 20 total points
ID: 2918665
Heres a sample proggie I wrote that extracts Microsoft Compressed files from an exe

program testsfx;
uses
  Classes,
  Lzexpand,
  Windows, Sysutils;
  {$R *.res}
var
yesno: integer;
WinDir: PChar;

// You will need to create a resource script and compile it with the Borland Resource Compiler and then make sure it is included as a resource in your exe
//
// Note, these files must be compressed with the Microsoft Compress Utility...
// A resource script that included one file, C:\test.ex_ would be
// yourfile exefile C:\test.ex_


procedure ExtractRes(ResType, ResName, ResNewName : String);
var
   Res : TResourceStream;
   begin
     Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
     Res.SavetoFile(ResNewName);
     Res.Free;
end;

function CopyFile( src, dest: String): Boolean;
   var
      s, d: TOFStruct;
      fs, fd: Integer;
      fnSrc, fnDest: PChar;
   begin
      src:=src + #0;
      dest:=dest + #0;
      fnSrc:=@src[1];   { Trick the Strings into being ASCIIZ }
      fnDest:=@dest[1];

      fs := LZOpenFile( fnSrc, s, OF_READ );    { Get file handles }
      fd := LZOpenFile( fnDest, d, OF_CREATE );

      if LZCopy( fs, fd ) < 0 then      { Here's the magic API call }
         Result:=False
      else
         Result:=True;

      LZClose( fs );    { Make sure to close 'em! }
      LZClose( fd );
   end;


begin
yesno:=MessageBox(0, 'This program will extract whatever version ??'#13
     +#13
     +'Continue with install?','SFX by Peter Windridge - pjw62@lineone.net',MB_ICONQUESTION + MB_YESNO);
     if yesno = IDYES then
     begin
  {$I-}
  MkDir('C:\extractpath\');
 
  ExtractRes('ExeFile', 'yourfile', 'C:\extractpath\yourfile.ex_');

  if CopyFile('C:\exractpath\yourfile.ex_', 'C:\extractpath\yourfile.exe') then
  MessageBox(0, 'extraction and expansion successful!','SFX by Peter Windridge - pjw62@lineone.net',MB_ICONQUESTION + MB_OK);

  end;
  end.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

695 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