I am using the following code which successfully copies a file from one
Folder to another. But the file gets corruped in the process.
In that the Active Property of the TTable component becomes False and if I try to make it True I get exception "Corrupt table/index header."
Also ...if I try and examine the copied file with Delphi Desktop I get a "Cannot open file" exception.
I might add I have tried including MyFile.px, by duplicating the routine below for that file - with the same result.
Any suggestions ....? Anyone??
procedure TfrmMyForem.btnCopyFileClick(Sender: TObject);
var
FileName, DestName: string;
CopyBuffer: Pointer; { buffer for copying }
BytesCopied: Longint;
Source, Dest: Integer; { handles }
Len: Integer;
Destination: TFileName; { holder for expanded destination name }
begin
DestName := ('c:\SecondFolder\MyFile.db');
Destination := ExpandFileName(DestName); { expand the destination path }
if HasAttr(Destination, faDirectory) then { if destination is a directory... }
begin
Len := Length(Destination);
FileName := ('c:\FirstFolder\MyFile.db');
if Destination[Len] = '\' then
Destination := Destination + ExtractFileName(FileName) { ...clone file name }
else
Destination := Destination + '\' + ExtractFileName(FileName); { ...clone file name }
end;
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }
if BytesCopied > 0 then { if we read anything... }
FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
until BytesCopied < ChunkSize; { until we run out of chunks }
finally
FileClose(Dest); { close the destination file }
end;
finally
FileClose(Source); { close the source file }
end;
finally
FreeMem(CopyBuffer, ChunkSize); { free the buffer }
end;
end;
Folder to another. But the file gets corruped in the process.
In that the Active Property of the TTable component becomes False and if I try to make it True I get exception "Corrupt table/index header."
Also ...if I try and examine the copied file with Delphi Desktop I get a "Cannot open file" exception.
I might add I have tried including MyFile.px, by duplicating the routine below for that file - with the same result.
Any suggestions ....? Anyone??
procedure TfrmMyForem.btnCopyFileClick(Sender: TObject);
var
FileName, DestName: string;
CopyBuffer: Pointer; { buffer for copying }
BytesCopied: Longint;
Source, Dest: Integer; { handles }
Len: Integer;
Destination: TFileName; { holder for expanded destination name }
begin
DestName := ('c:\SecondFolder\MyFile.db');
Destination := ExpandFileName(DestName); { expand the destination path }
if HasAttr(Destination, faDirectory) then { if destination is a directory... }
begin
Len := Length(Destination);
FileName := ('c:\FirstFolder\MyFile.db');
if Destination[Len] = '\' then
Destination := Destination + ExtractFileName(FileName) { ...clone file name }
else
Destination := Destination + '\' + ExtractFileName(FileName); { ...clone file name }
end;
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }
if BytesCopied > 0 then { if we read anything... }
FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
until BytesCopied < ChunkSize; { until we run out of chunks }
finally
FileClose(Dest); { close the destination file }
end;
finally
FileClose(Source); { close the source file }
end;
finally
FreeMem(CopyBuffer, ChunkSize); { free the buffer }
end;
end;