Delphi: Copy files and free space on drives


[ Delphi Forum ]

Posted by Joey on February 18, 2004 at 23:40:25:

I am currently working on copying files without using the CopyFile function. The code i am using is taken from the torry site again:

procedure FastFileCopy(const InFileName, OutFileName: string; 
  CallBack: TCallBack); 
const 
  BufSize = 3 * 4 * 4096; { 48Kbytes gives me the best results } 
type 
  PBuffer = ^TBuffer; 
  TBuffer = array[1..BufSize] of Byte; 
var 
  Size: DWORD; 
  Buffer: PBuffer; 
  infile, outfile: file; 
  SizeDone, SizeFile: LongInt; 
begin 
  if (InFileName  OutFileName) then 
  begin 
    buffer := nil; 
    Assign(infile, InFileName); 
    Reset(infile, 1); 
    try 
      SizeFile := FileSize(infile); 
      Assign(outfile, OutFileName); 
      Rewrite(outfile, 1); 
      try 
        SizeDone := 0; 
        New(Buffer); 
        repeat 
          BlockRead(infile, Buffer^, BufSize, Size); 
          Inc(SizeDone, Size); 
          CallBack(SizeDone, SizeFile); 
          BlockWrite(outfile, Buffer^, Size) 
        until Size  nil then 
          Dispose(Buffer); 
        CloseFile(outfile) 
      end; 
    finally 
      CloseFile(infile); 
    end; 
  end 
  else 
    raise EInOutError.Create('File cannot be copied onto itself') 
end;

What i want to know is... Where the Buffersize is set (in this case to 48kb) how can i make it so it would be as fast as your computer can handle?? Coz i know delphi can support upto 2gb with this but some (alot) of computers wouldnt be able to transfer it at that speed... Is there away to work out how fast it can be? and what it this based on?? (i.e. memory or something?)

The second question is how do i get the amounst of free space on a drive?? As i dont want to transfer if the destination cannot hold that amount of files! ;)

Thx in advance :):):):):):):)


Related Articles and Replies:


[ Delphi Forum ]