classic_gaming
asked on
inserting a file into another file
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
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
ASKER
it's exactly how you described it.
i need to put a file into another file.
i need to put a file into another file.
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 :-)
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 :-)
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
Description of working with TZipMaster
http://www.latiumsoftware.com/en/pascal/0005.php3
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 :-)
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
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 :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
geobul thats perfect points to you :)
i wanted a non-component solution and you gave me the actual source way of doing it.
cheers
i wanted a non-component solution and you gave me the actual source way of doing it.
cheers
ASKER
hi,
could you modify that so it can do multiple files?
i'll throw in an extra 50points :)
could you modify that so it can do multiple files?
i'll throw in an extra 50points :)
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.Creat e(Dest+':' +StreamNam e, fmCreate);
OldFile:=TFileStream.Creat e(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.Creat e(Source+' :'+StreamN ame, fmShareDenyNone);
NewFile:=TFileStream.Creat e(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.tx t','c:\tem p\test1.do c','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\tes t1.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 ',ExtractF ileName(Th irdFile));
end;
end.
Regards, Geo
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.Creat
OldFile:=TFileStream.Creat
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.Creat
NewFile:=TFileStream.Creat
NewFile.CopyFrom(OldFile, OldFile.Size);
FreeAndNil(OldFile);
FreeAndNil(NewFile);
end;
// add 'c:\test2.txt' to 'c:\temp\test1.doc'
procedure TForm1.Button1Click(Sender
begin
AddSecondFile('c:\test2.tx
end;
// extract the second file to another directory 'c:\temp\test2.txt'
procedure TForm1.Button2Click(Sender
begin
ExtractSecondFile('c:\temp
end;
// add 'c:\test3.txt' to 'c:\temp\test1.doc'
procedure TForm1.Button3Click(Sender
begin
AddSecondFile(ThirdFile,'c
end;
// extract the third file to another directory 'c:\temp\test3.txt'
procedure TForm1.Button4Click(Sender
begin
ExtractSecondFile('c:\temp
end;
end.
Regards, Geo
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 :-)