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

有關於檔案是否已被開啟的判斷問題

尚未結案
Jack0323
初階會員


發表:22
回覆:70
積分:28
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-05-03 23:41:31 IP:211.74.xxx.xxx 未訂閱
請問各位高手們: 我用了hagar 版大的範例 http://delphi.ktop.com.tw/topic.php?topic_id=26986 去判讀某個TXT檔是否已被開啟(事實上我己經用記事本開啟了) 但是結果確是傳回False 不知道要如何才能真正判斷某TXT檔已經被開啟了
Fishman
尊榮會員


發表:120
回覆:1949
積分:2163
註冊:2006-10-28

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-05-04 08:40:59 IP:210.65.xxx.xxx 未訂閱
Hi Jack0323,    以下幾篇討論供你參考 http://delphi.ktop.com.tw/topic.php?topic_id=40148 http://delphi.ktop.com.tw/topic.php?topic_id=45245 http://delphi.ktop.com.tw/topic.php?topic_id=45830 ---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman
Jack0323
初階會員


發表:22
回覆:70
積分:28
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-05-04 11:45:36 IP:211.74.xxx.xxx 未訂閱
謝謝Fishman兄的回應: 您提供的這些範例我都已看過 但是我還是不明白 雖然以NotPad開啟後,檔案在Locked狀態 如果用專用開啟,那理論上來說不是應該開不起來才對嗎 但是我用NotPad開啟後,用下面的function測試確仍為False 不是應該會有錯誤代碼嗎 真的是很不了解 還希望各位大大幫忙 是不是我的觀念那裡不對 先謝謝大家了 function FileLocked(Fn: string): Boolean; var I : Integer; Struct: TOfStruct; Style: Cardinal; Hdl: Hfile; Drive: String; begin Style := OF_Share_Exclusive; //排它方式打開 Drive := UpperCase(Fn[1]); Struct.fFixedDisk := Ord(Drive <> 'A'); //判斷是否是硬碟 Struct.cBytes := SizeOf(Struct); For I := 1 to Length(Fn) do Struct.szPathName[I-1] := Fn[I]; Struct.szPathName[I] := Chr(0); //填充文件名 Hdl := OpenFile(Pchar(Fn), Struct, Style); if Hdl = HFILE_ERROR then begin Result := True; //文件被鎖定 Showmessage(SysErrorMessage(GetLastError)); //顯示錯誤原因 end else Result := False; CloseHandle(Hdl); end;
Fishman
尊榮會員


發表:120
回覆:1949
積分:2163
註冊:2006-10-28

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-05-04 12:32:38 IP:210.65.xxx.xxx 未訂閱
Hi Jack0323,    請參見 http://delphi.ktop.com.tw/topic.php?topic_id=45245 中,william 版大的說明
引言: For Notepad and Wordpad, the WHOLE file is being read into the application's memory and closed. You can even delete the file afterwards. So I think the best you can do is detecting whether the file is being opened (i.e. fail in acquiring an exlusing lock) or not. Refering to your original question, please test if your ftp server should hold a lock on the file during transfer (probably yes). Or you could use the file creation/modification datetime for some kind of additional reference.
我想這就是無法偵測該檔案已被 NotePad,WordPad 開啟的主因吧! ---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman
系統時間:2024-05-21 23:15:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!