Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing/Adding file Header 1

Status
Not open for further replies.

JanChlpik

Technical User
May 10, 2008
10
CZ
Hi I have nearly finished converting program, but what looked easy is impossible to finish for me. Its image(picture) file btw

First I assign file(that works fine)

AssignFile(Myfile, Filelist);

If I managed to convert it to string I would simply type
Delete(Myfile,1,20)

But I did not find any way how to navigate(using Myfile[j] does not work) to read and rewrite into buffer file without the first 20chars.

Next I need to do the same, but insert.

Sorry to bother, but I was trying to search through help and internet and was not able to find working solution.
 
I'm not sure I'm understanding your question. You're wanting to work around a file header that contains different information than the main? In other words, how to work with a file that has differing types in it?

----------
Those who work hard are rewarded with more work and remembered come time to downsize. Those who hardly work are given a paycheck and ignored completely.
 
Well I need to remove header, which is 20x4bytes and then place it back. But cant find the right command
 
You mean change it?

Untyped files:

Code:
var
  myfile: File;
  unit1: array[1..20] of integer;
  unit2: array[1..10] of char;
begin
  AssignFile(myfile, 'test.dat');
  reset(myfile, 1);
  {read first unit}
  blockread(myfile, unit1, sizeof(unit1));
  { read second unit}
  blockread(myfile, unit2, sizeof(unit2));
  CloseFile(myfile);
end.

Maybe I am unclear still on what you are wanting to do? Using blockwrite will overwrite at current position if file is reset as opposed to rewrite.


----------
Those who work hard are rewarded with more work and remembered come time to downsize. Those who hardly work are given a paycheck and ignored completely.
 
var
myfile, Newfile: File;
unit1: array[1..20] of byte;
begin
AssignFile(myfile, 'test.dat');
reset(myfile, 1);
blockread(myfile, unit1, sizeof(unit1));
CloseFile(myfile);
end.

K I use block read, but I want to skip first block and read and write the rest to new file.

Sorry for confusing you.
 
Code:
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
var NewFileName: string;
var MyFile: File;
var unit1 : byte;
begin
Memo1.Clear;
{$I+}
For i:= 0 to Filelist.Count - 1  do
  begin
  AssignFile(Myfile, Filelist[i]);
  Reset(Myfile,1);
  Blockwrite(MyFile, unit1,20);
  CloseFile(MyFile);
  NewFileName := ChangeFileExt(Filelist[i],'.dds');
  RenameFile(Filelist[i],NewFileName);
  Memo1.Lines.Append ('Converted to ' + ExtractFileName(NewFileName) + ' successfuly.');
  Button1.Enabled := false;
 end;
 {$I-}
 end;
 
Well, reading or seeking past the value would help.

Untested:
Code:
var
  infile, outfile: file;
  buf1: array[1..2048] of char;
  amount_read: integer;
begin
  AssignFile(Infile, 'IN.DAT');
  AssignFile(Outfile, 'OUT.DAT');
  Reset(Infile, 1);
  Rewrite(Outfile, 1);
  { move initial infile }
  Blockread(Infile, buf1, 20);
  blockread(Infile, Buf1, sizeof(buf1), amount_read);
  repeat
    blockwrite(Outfile, Buf1, amount_read);
    blockread(Infile, Buf1, sizeof(buf1), amount_read);
  until amount_read = 0;
  CloseFile(Infile);
  CloseFile(Outfile);
end.  

----------
Those who work hard are rewarded with more work and remembered come time to downsize.  Those who hardly work are given a paycheck and ignored completely.
 
Thanks it works fine, now just need to create new file and use it(instead using existing one). Well dont understand how exactly amount_read works, but thats minor problem. Thanks for solution I think can do the rest myself.
 
Well dont understand how exactly amount_read works, but thats minor problem.

amount_read is a variable that stores exactly how much was read in by the blockread.

----------
Those who work hard are rewarded with more work and remembered come time to downsize. Those who hardly work are given a paycheck and ignored completely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top