全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2612
推到 Plurk!
推到 Facebook!

如何SHOW檔案列表

答題得分者是:pceyes
andyy7491168
一般會員


發表:2
回覆:1
積分:0
註冊:2008-07-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-07-24 10:19:28 IP:220.130.xxx.xxx 訂閱
各位大大,小弟我想做一樣功能,就是假設我C:\temp\ 有許多檔案以及資料夾、該資料夾內又有許多檔案,請問一下我要如何達成可以將這些檔案列表show在memo上呢?
而且還要捉取這些檔案的修改日期、及檔案大小?
當然最理想的結果如下:
C:\temp
xx1.txt 2008/7/24 10kb
xx2.txt 2008/7/24 10kb
xx3.txt 2008/7/24 10kb
C:\temp\test\
tt1.txt 2008/7/24 10kb
tt1.txt 2008/7/24 10kb
tt1.txt 2008/7/24 10kb

感謝各位大大回答。
編輯記錄
andyy7491168 重新編輯於 2008-07-24 10:56:36, 註解 無‧
andyy7491168 重新編輯於 2008-07-25 09:34:52, 註解 無‧
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-07-24 15:30:40 IP:220.141.xxx.xxx 訂閱
1. 取得目錄下的所有檔案(含次目錄)
難以歸類主題的討論區(Delphi) » 檔案搜尋不會進入每個子目錄?!
http://delphi.ktop.com.tw/board.php?cid=30&fid=69&tid=90014
[code delphi]
procedure GETMYFILE(SOURCEPATH: string);
var SR: TSEARCHREC;
begin
Sourcepath := IncludeTrailingPathDelimiter(Sourcepath);
if FINDFIRST(sourcepath '\*.*', faanyfile, sr) = 0 then begin
repeat
if (sr.name <> '.') and (sr.name <> '..') then begin
if (sr.attr and faDirectory) <> faDirectory then begin
Form1.MEMO1.LINES.ADD(sourcepath sr.name);
end else begin
getmyfile(sourcepath sr.name);
end;
end;
until findnext(sr) <> 0;
end;
findclose(sr);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GETMYFILE('d:\delphi_test');
end;

[/code]
------
努力會更接近成功
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-07-24 15:40:03 IP:220.141.xxx.xxx 訂閱
2. 取得檔案修改日期
Win32 API 使用討論區(Delphi) » 讀取建檔日期與修改日期
http://delphi.ktop.com.tw/board.php?cid=30&fid=72&tid=80855

[code delphi]
function GetFileDate(const FileName: string; out Creation, LastAccess,
LastWrite: TDateTime): Boolean;
var
hFile: THandle;
ftCreationUTC, ftLastAccessUTC, ftLastWriteUTC: TFileTime;
ftCreationLocal, ftLastAccessLocal, ftLastWriteLocal: TFileTime;
stCreationLocal, stLastAccessLocal, stLastWriteLocal: TSystemTime;
begin
result:=false;
hFile := CreateFile(PChar(FileName), GENERIC_READ, 0, nil,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
if (hFile <> INVALID_HANDLE_VALUE) then begin
try
if GetFileTime(hFile, @ftCreationUTC, @ftLastAccessUTC, @ftLastWriteUTC) then begin
if FileTimeToLocalFileTime(ftCreationUTC, ftCreationLocal)
and FileTimeToLocalFileTime(ftLastAccessUTC, ftLastAccessLocal)
and FileTimeToLocalFileTime(ftLastWriteUTC, ftLastWriteLocal) then begin
if FileTimeToSystemTime(ftCreationLocal, stCreationLocal)
and FileTimeToSystemTime(ftLastAccessLocal, stLastAccessLocal)
and FileTimeToSystemTime(ftLastWriteLocal, stLastWriteLocal) then begin
Creation := SystemTimeToDateTime(stCreationLocal);
LastAccess := SystemTimeToDateTime(stLastAccessLocal);
LastWrite := SystemTimeToDateTime(stLastWriteLocal);
result:=true;
end;
end;
end;
finally
CloseHandle(hFile);
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
creation, lastaccess, lastwrite: TDateTime;
begin
if OpenDialog1.Execute then
GetFileDate(OpenDialog1.FileName, creation, lastaccess, lastwrite);
ShowMessage('建立時間: ' DateTimeToStr(creation) #13#10 '訪問時間: '
DateTimeToStr(lastaccess) #13#10 '修改時間: ' DateTimeToStr(lastwrite));
end;

[/code]
------
努力會更接近成功
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-07-24 15:48:13 IP:220.141.xxx.xxx 訂閱
3. 取得檔案大小
Object Pascal物件導向討論區(Delphi) » 如何得知正在執行的EXE檔檔案大小
http://delphi.ktop.com.tw/board.php?cid=30&fid=70&tid=64218

好了, 你要的討論區裏面通通都有,

檔案列表、修改日期、檔案大小、

我也幫你找出來了,剩下的只要兜起就好了。

有delphi.ktop真好!
------
努力會更接近成功
andyy7491168
一般會員


發表:2
回覆:1
積分:0
註冊:2008-07-24

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-07-25 09:33:47 IP:220.130.xxx.xxx 訂閱
小弟煩惱了好久,感謝大大解惑。
編輯記錄
andyy7491168 重新編輯於 2008-07-25 11:22:42, 註解 無‧
系統時間:2024-04-28 13:50:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!