?
Solved

how to copy an open text file in delphi

Posted on 2003-02-20
6
Medium Priority
?
376 Views
Last Modified: 2010-04-04
hi

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



thanx
0
Comment
Question by:Zaheer
[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
6 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 7988112
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
 
LVL 27

Accepted Solution

by:
kretzschmar earned 400 total points
ID: 7988275
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
 

Expert Comment

by:RAGAB2000
ID: 7992212
I think kretzschmar in his last solution is right
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 9

Expert Comment

by:mocarts
ID: 7992644
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
 
LVL 21

Expert Comment

by:ziolko
ID: 7993899
yep kretzschmar you're absolutelly right.
ziolko.
0
 

Expert Comment

by:CleanupPing
ID: 9317155
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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