how to copy an open text file in delphi

hi

can anyone one advise me on how to copy an open Text file in delphi ?



thanx
ZaheerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ziolkoCommented:
You can use TStrings.LoadFromFile or
var F: TextFile;

AssignFile(F,FileName);
Reset(F);
try
while not Eof(F) do
begin
  do here anything You want useing ReadLn(F,...);
end;
finally
CloseFile(F);
end;

ziolko.
0
kretzschmarCommented:
wont work ziolko,

first you must change the filemode to readonly
(default is readwrite)

AssignFile(F,FileName);
filemode := 0; //<--- readonly
Reset(F);
try
while not Eof(F) do
begin
 do here anything You want useing ReadLn(F,...);
end;
finally
CloseFile(F);
end;

but i would prefer two two tfilestreams
like

var
  source, dest : TFileStream;
begin
  try
    source := TfileStream.Create('SourceFileName',fmOpenRead);
    try
      dest := TfileStream.Create('DestFileName',fmCreate);
      try
        dest.CopyFrom(source,0);
      finally
        dest.free;
      end;
    finally
      source.free;
    end;
  except
    Showmessage(SomeThing went wrong');
    raise;
  end;
end;

well just from hrad
not tested

meikl ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RAGAB2000Commented:
I think kretzschmar in his last solution is right
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

mocartsCommented:
if you don't write corssplatform app you can also use:

  Windows.CopyFile(lpExistingFileName, lpNewFileName: PChar; bFailIfExists: BOOL): BOOL;

copiing is impossible if file is opened without rights to others to read.

wbr, mo.
0
ziolkoCommented:
yep kretzschmar you're absolutelly right.
ziolko.
0
CleanupPingCommented:
Zaheer:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.