怎样实现文件copy? (十万火急)(100分)

  • 主题发起人 主题发起人 soloxu
  • 开始时间 开始时间
procedure TForm1.Button1Click(Sender: TObject);
var
ErrorMessage: Pointer; // holds a system error string
ErrorCode: DWORD; // holds a system error code
begin
{blank out the status bar}
StatusBar1.SimpleText:='';

{attempt to copy the file}
if not CopyFile(PChar(Edit1.Text+'/'+ExtractFilename
(FileListBox1.FileName)),
PChar(Edit2.Text+'/'+ExtractFilename
(FileListBox1.FileName)),

not CheckBox1.Checked) then
begin
{if the file was not copied, display the error message}
ErrorCode := GetLastError;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER or
FORMAT_MESSAGE_FROM_SYSTEM,
nil, ErrorCode, 0, @ErrorMessage, 0, nil);
StatusBar1.SimpleText:='Error Copying File: '+string(PChar
(ErrorMessage));
LocalFree(hlocal(ErrorMessage));
end;
end;
 
var
f1,f2: TextFile;
S: string;
begin
AssignFile(f1, 'filename1'); Reset(f1);
AssignFile(f2, 'filename2'); ReWrite(f2);
while not f1.eof do
begin
Readln(f1, S);
WriteLn(f2,S);
end;
CloseFile(f1);
CloseFile(f2);
end;
 
Procedure FileCopy( Const sfilename, tfilename: String );
Var
Sou, Ta: TFileStream;
Begin
Sou := TFileStream.Create( sfilename, fmOpenRead );
try
Ta := TFileStream.Create( tfilename, fmOpenWrite or fmCreate );
try
Ta.CopyFrom(Sou, Sou.Size )
finally
Ta.Free;
end;
finally
Sou.Free;
end;
End;
 
uses LZExpand;
procedure CopyFile(SourceFile, DestinationFile: TFileName);
var
hSource, hDestination : Integer;
buf: TOFStruct;
begin
try
hSource := LZOpenFile(PChar(SourceFile), buf, OF_READ);
if (hSource>0) then
begin
hDestination := LZOpenFile(PChar(DestinationFile), buf, OF_CREATE);
if (hDestination>0) then
begin
Num := LzCopy(hSource, hDestination);
LzClose(hDestination);
end;
LzClose(hSource);
end;
except
end;
end;
 
Fudei的方法最好,可以给分了.(可惜我来晚了)
 
多人接受答案了。
 
后退
顶部