Try to create non fragmented files on copy/move
Posted: 2007-11-04, 15:06 UTC
Hi Christian,
I noticed that TC creates fragmented files when copying or moving files.
In the article "Fix verteilt" from the heise magazin "c't" 21/2005 about fragmentation they suggested to use the Windows-API-Functions SetFilePointer() and SetEndOfFile() like in this Delphi 7 sample:
(only tested on NTFS from Win XP)
If there is enough free space on disk, this will work in most cases. Nevermind if not, the handle is always there.
Maybe in future versions...
Greets and thanks for this great piece of software.
maxB
I noticed that TC creates fragmented files when copying or moving files.
In the article "Fix verteilt" from the heise magazin "c't" 21/2005 about fragmentation they suggested to use the Windows-API-Functions SetFilePointer() and SetEndOfFile() like in this Delphi 7 sample:
(only tested on NTFS from Win XP)
Code: Select all
var dstHandle: Integer;
srcname, dstname: string;
filesize: Int64;
li: LARGE_INTEGER;
success: longbool;
sr : TSearchRec;
begin
// get size of source file
srcname:='c:\1.bin';
if FindFirst(srcname, faAnyFile, sr)=0 then
filesize:=Int64(sr.FindData.nFileSizeHigh * 4294967295) + Int64(sr.FindData.nFileSizeLow);
FindClose(sr);
// open destination file
dstname:='c:\2.bin';
dstHandle:=FileCreate(dstname);
li.QuadPart:=filesize;
// set filepointer to size of source file
if (SetFilePointer(Cardinal(dstHandle), li.LowPart, @li.HighPart, FILE_BEGIN) <> -1) then
// set the end of the destination file so that the
// filesystem knows how long the file will be
success:=SetEndOfFile(Cardinal(dstHandle))
else
success:=FALSE;
// set back the filepointer to start of destination file
SetFilePointer(Cardinal(dstHandle), 0, nil, FILE_BEGIN);
// file-operation...
FileClose(dstHandle);
end;
Maybe in future versions...
Greets and thanks for this great piece of software.
maxB