|
Tested
the question below - a file has same number on NTFS and
FAT32
I am
using code like this as alternative way to copy a file using
FileStream.
Like
it that the copy is done in one line using CopyFrom :) - the rest is
just housekeeping and checking.
(got
some ideas from Google- as I could not find your example in the D2006
help)
so far
seems to work fine...if anyone has suggestions for improvement add
them.
function
xffsCopyFile(aFile1:string;aFile2:string):int64;
//returns number bytes copied, -1 if not successful var FileSize1,FileSize2,bytescopied:int64; fs1,fs2:TFileStream; FileAge1,FileAge2:integer; begin result:=0; bytescopied:=0; fs1 := TFileStream.Create(aFile1, fmOpenRead); try fs2 := TFileStream.Create(aFile2, fmCreate); try {Forget about block reads and writes, just copy the whole darn thing.} bytescopied:=fs2.CopyFrom(fs1, 0); finally fs2.Free; end; finally fs1.Free; end; result:=bytescopied; //alter file dateTime Stamp to match original file if (FileExists(aFile1)) and (FileExists(aFile2)) then begin FileSize1:=xffsFileSize(aFile1); FileSize2:=xffsFileSize(aFile2); FileAge1:=FileAge(aFile1); FileAge2:=FileAge(aFile2); if (FileSize1=FileSize2) and(FileSize2=bytescopied) and(FileAge2>FileAge1) then begin //only set date if copied right size and date of //File2 now later than File1 FileSetDate(aFile2,FileAge1); end else result:=-1; //signal error end; end; function
xffsFileSize(Filename:string):int64;
var fs:TFileStream; begin result:=0; if FIleExists(Filename) then begin try fs:=Tfilestream.create(FileName,fmOpenRead or fmShareDenyNone); //more code for I/U fs.seek(0,soFromBeginning); result:=fs.size; finally fs.free; end; end; end; John Bird
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Bird Sent: Friday, 22 September 2006 12:07 p.m. To: 'Conor Boyd'; 'NZ Borland Developers Group - Delphi List' Subject: RE: [DUG] Copying files problem
|
_______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
