Registriert seit: 23. Jan 2003
Ort: Sandbeiendorf
360 Beiträge
Delphi 8 Professional
|
Re: Datei wird nicht kopiert in Win2000/XP
14. Apr 2005, 14:52
Hallo Christian,
ich habe aus FMXUtils (Delphi/Docs) die Procedure Copyfile benutzt, welche sonst immer funktioniert, nur dort nicht.
mfg
Delphi-Quellcode:
procedure CopyFile(const FileName, DestName: string);
var
CopyBuffer: Pointer; { buffer for copying }
BytesCopied: Longint;
Source, Dest: Integer; { handles }
Len: Integer;
Destination: TFileName; { holder for expanded destination name }
const
ChunkSize: Longint = 8192; { copy in 8K chunks }
begin
Destination := ExpandFileName(DestName); { expand the destination path }
if HasAttr(Destination, faDirectory) then { if destination is a directory... }
begin
Len := Length(Destination);
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 }
if Source < 0 then raise EFOpenError.CreateFmt(SFOpenError, [FileName]);
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
if Dest < 0 then raise EFCreateError.CreateFmt(SFCreateError, [Destination]);
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;
|
|
Zitat
|