線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1439
推到 Plurk!
推到 Facebook!

請問一個function

尚未結案
totodog
一般會員


發表:13
回覆:3
積分:3
註冊:2003-05-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-20 16:47:41 IP:61.220.xxx.xxx 未訂閱
請問一下各位先進: 我在windows下寫一個開檔的程式用到一個 function 叫做filelength來抓取檔案的長度, 但是移植到linux後 linux好像沒有這一個funuction 請問是function name 改變嗎?還是沒有這一個function 那要是沒有的話 我怎樣用替代的function來代替它ㄋ?
Leeway
一般會員


發表:2
回覆:18
積分:4
註冊:2003-06-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-23 17:35:48 IP:211.20.xxx.xxx 未訂閱
此為 php 函數,不知是否適用.....^^" filesize --- 取得檔案的大小 語法 : int filesize (string filename) 說明 : 傳回檔案的大小,發生錯誤則傳回false。 此函式的結果會存在快取緩衝區中,詳細資料請參考clearstatcache( )。
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-23 18:14:25 IP:202.39.xxx.xxx 未訂閱
是在 Kylix 下嗎?是的話, 參考紅色部份: http://www.swissdelphicenter.ch/torry/showcode.php?id=330
procedure TForm1.CopyFileWithProgressBar1(Source, Destination: string); 
var 
  FromF, ToF: file of byte; 
  Buffer: array[0..4096] of char; 
  NumRead: integer; 
  FileLength: longint; 
begin 
  AssignFile(FromF, Source); 
  reset(FromF); 
  AssignFile(ToF, Destination); 
  rewrite(ToF); 
  FileLength := FileSize(FromF);
  with Progressbar1 do 
  begin 
    Min := 0; 
    Max := FileLength; 
    while FileLength > 0 do 
    begin 
      BlockRead(FromF, Buffer[0], SizeOf(Buffer), NumRead); 
      FileLength := FileLength - NumRead; 
      BlockWrite(ToF, Buffer[0], NumRead); 
      Position := Position   NumRead; 
    end; 
    CloseFile(FromF); 
    CloseFile(ToF); 
  end; 
end;     procedure TForm1.Button1Click(Sender: TObject); 
begin 
  CopyFileWithProgressBar1('c:\Windows\Welcome.exe', 'c:\temp\Welcome.exe'); 
end;     { 2. }     {***************************************}     // To show the estimated time to copy a file:     procedure TForm1.CopyFileWithProgressBar1(Source, Destination: string); 
var 
  FromF, ToF: file of byte; 
  Buffer: array[0..4096] of char; 
  NumRead: integer; 
  FileLength: longint; 
  t1, t2: DWORD; 
  maxi: integer; 
begin 
  AssignFile(FromF, Source); 
  reset(FromF); 
  AssignFile(ToF, Destination); 
  rewrite(ToF); 
  FileLength := FileSize(FromF); 
  with Progressbar1 do 
  begin 
    Min  := 0; 
    Max  := FileLength; 
    t1   := TimeGetTime; 
    maxi := Max div 4096; 
    while FileLength > 0 do 
    begin 
      BlockRead(FromF, Buffer[0], SizeOf(Buffer), NumRead); 
      FileLength := FileLength - NumRead; 
      BlockWrite(ToF, Buffer[0], NumRead); 
      t2  := TimeGetTime; 
      Min := Min   1; 
      // Show the time in Label1 
      label1.Caption := FormatFloat('0.00', ((t2 - t1) / min * maxi - t2   t1) / 100); 
      Application.ProcessMessages; 
      Position := Position   NumRead; 
    end; 
    CloseFile(FromF); 
    CloseFile(ToF); 
  end; 
end;     { 3. } 
{***************************************} 
// To show the estimated time to copy a file, using a callback function:     type 
  TCallBack = procedure(Position, Size: Longint); { export; }     procedure FastFileCopy(const InFileName, OutFileName: string; 
  CallBack: TCallBack);     implementation     procedure FastFileCopyCallBack(Position, Size: Longint); 
begin 
  Form1.ProgressBar1.Max := Size; 
  Form1.ProgressBar1.Position := Position; 
end;     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 < BufSize; 
        FileSetDate(TFileRec(outfile).Handle, 
        FileGetDate(TFileRec(infile).Handle)); 
      finally 
        if Buffer <> nil then 
          Dispose(Buffer); 
        CloseFile(outfile) 
      end; 
    finally 
      CloseFile(infile); 
    end; 
  end 
  else 
    raise EInOutError.Create('File cannot be copied onto itself') 
end; {FastFileCopy}         procedure TForm1.Button1Click(Sender: TObject); 
begin 
  FastFileCopy('c:\daten.txt', 'c:\test\daten2.txt', @FastFileCopyCallBack); 
end;     { 4. } 
{***************************************}     function CopyFileWithProgressBar2(TotalFileSize, 
  TotalBytesTransferred, 
  StreamSize, 
  StreamBytesTransferred: LARGE_INTEGER; 
  dwStreamNumber, 
  dwCallbackReason: DWORD; 
  hSourceFile, 
  hDestinationFile: THandle; 
  lpData: Pointer): DWORD; stdcall; 
begin 
  // just set size at the beginning 
  if dwCallbackReason = CALLBACK_STREAM_SWITCH then 
    TProgressBar(lpData).Max := TotalFileSize.QuadPart;       TProgressBar(lpData).Position := TotalBytesTransferred.QuadPart; 
  Application.ProcessMessages; 
  Result := PROGRESS_CONTINUE; 
end;     function TForm1.CopyWithProgress(sSource, sDest: string): Boolean; 
begin 
  // set this FCancelled to true, if you want to cancel the copy operation 
  FCancelled := False; 
  Result     := CopyFileEx(PChar(sSource), PChar(sDest), @CopyFileWithProgressBar2, 
    ProgressBar1, @FCancelled, 0); 
end;     end;     
系統時間:2024-05-17 0:43:23
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!