Solved

inserting a file into another file

Posted on 2002-04-19
9
158 Views
Last Modified: 2010-04-04
hi,

i was wondering if this could be possible i have a temp.temp file as the file i want to store stuff in, but i want to put test.doc in there.

anyone know a way of inserting it in there and extracting it to a temp folder for accessing it.

cheers
0
Comment
Question by:classic_gaming
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:Gwena
ID: 6954460
I am not certain what you want here..


Do you have a file on disk ...lets say it's temp.dat
and you want to be able to add other files to this file
and extract them later... like put test.doc in there and later pull it out and put it in another folder...or in a memstream or something??


This is pretty simple to do if this is what you need...
please explain what you want a little a little more :-)
0
 

Author Comment

by:classic_gaming
ID: 6954535
it's exactly how you described it.

i need to put a file into another file.
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 6955251
Hello!

Check these components out(the are free with sources):
1)http://www.torry.net/vcl/filedrv/files/stuffit.zip
2)http://www.torry.net/vcl/filedrv/files/pakit.zip

Good Luck :-)
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Expert Comment

by:lottol
ID: 6955743
you can work  with your temp fils as zip archive, using for example TZipMaster component

Description of working with TZipMaster
http://www.latiumsoftware.com/en/pascal/0005.php3
0
 
LVL 5

Expert Comment

by:Gwena
ID: 6955770
Hi :-)

  Go to my website http://delphi.does.it

and check out the file called newdemo1.zip it contains a demo w/source that shows how to add files to an exe file at runtime... and later extract them to disk. You can do the same thing with any external file... adding files to it and then later extracting the individual files.

The file that you add other files to could be anything...exe,txt,mp3,pdf..whatever.  and remember that you can add your files to your exe if you wish :-)

If the demo looks like what you want to do using an external file then I can make a demo for that and send it to you :-)
0
 
LVL 17

Accepted Solution

by:
geobul earned 200 total points
ID: 6955986
Hi,

You can easily add one (only one) file to another and extract it later:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

// adds Source file to Dest file
procedure AddSecondFile(Source, Dest: string);
var
 NewFile: TFileStream;
 OldFile: TFileStream;
begin
 NewFile:=TFileStream.Create(Dest+':geobul', fmCreate);
 OldFile:=TFileStream.Create(Source, fmShareDenyNone);
 NewFile.CopyFrom(OldFile, OldFile.Size);
 FreeAndNil(OldFile);
 FreeAndNil(NewFile);
end;

// Extract second file to Dest file
procedure ExtractSecondFile(Source, Dest: string);
var
 NewFile: TFileStream;
 OldFile: TFileStream;
begin
 OldFile:=TFileStream.Create(Source+':geobul', fmShareDenyNone);
 NewFile:=TFileStream.Create(Dest, fmCreate);
 NewFile.CopyFrom(OldFile, OldFile.Size);
 FreeAndNil(OldFile);
 FreeAndNil(NewFile);
end;

// add 'c:\test2.txt' to 'c:\temp\test1.doc'
procedure TForm1.Button1Click(Sender: TObject);
begin
  AddSecondFile('c:\test2.txt','c:\temp\test1.doc');
end;

// extract the second file to another directory 'c:\temp\test2.txt'
procedure TForm1.Button2Click(Sender: TObject);
begin
  ExtractSecondFile('c:\temp\test1.doc','c:\temp\test2.txt');
end;

end.

Regards, Geo
0
 

Author Comment

by:classic_gaming
ID: 6956380
geobul thats perfect points to you :)

i wanted a non-component solution and you gave me the actual source way of doing it.

cheers
0
 

Author Comment

by:classic_gaming
ID: 6956502
hi,

could you modify that so it can do multiple files?

i'll throw in an extra 50points :)
0
 
LVL 17

Expert Comment

by:geobul
ID: 6962633
Hi,

Yes, the following does it. You have to remember which StreamName was used for each file. It could be the original filename (the second file here) or something else (the first file here):

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  ThirdFile:string = 'c:\test3.txt';

// adds Source file to Dest file
procedure AddSecondFile(Source, Dest, StreamName: string);
var
 NewFile: TFileStream;
 OldFile: TFileStream;
begin
 NewFile:=TFileStream.Create(Dest+':'+StreamName, fmCreate);
 OldFile:=TFileStream.Create(Source, fmShareDenyNone);
 NewFile.CopyFrom(OldFile, OldFile.Size);
 FreeAndNil(OldFile);
 FreeAndNil(NewFile);
end;

// Extract second file to Dest file
procedure ExtractSecondFile(Source, Dest, StreamName: string);
var
 NewFile: TFileStream;
 OldFile: TFileStream;
begin
 OldFile:=TFileStream.Create(Source+':'+StreamName, fmShareDenyNone);
 NewFile:=TFileStream.Create(Dest, fmCreate);
 NewFile.CopyFrom(OldFile, OldFile.Size);
 FreeAndNil(OldFile);
 FreeAndNil(NewFile);
end;

// add 'c:\test2.txt' to 'c:\temp\test1.doc'
procedure TForm1.Button1Click(Sender: TObject);
begin
  AddSecondFile('c:\test2.txt','c:\temp\test1.doc','file1');
end;

// extract the second file to another directory 'c:\temp\test2.txt'
procedure TForm1.Button2Click(Sender: TObject);
begin
  ExtractSecondFile('c:\temp\test1.doc','c:\temp\test2.txt','file1');
end;

// add 'c:\test3.txt' to 'c:\temp\test1.doc'
procedure TForm1.Button3Click(Sender: TObject);
begin
  AddSecondFile(ThirdFile,'c:\temp\test1.doc', ExtractFileName(ThirdFile));
end;

// extract the third file to another directory 'c:\temp\test3.txt'
procedure TForm1.Button4Click(Sender: TObject);
begin
   ExtractSecondFile('c:\temp\test1.doc','c:\temp\test3.txt',ExtractFileName(ThirdFile));
end;

end.

Regards, Geo
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 69
delphi parse string to params 3 123
I want to use librsync in my Delphi backup application. 3 50
scroll down TListBox component in Delphi 1 11
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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