delphi下檔案查詢findfirst

2021-06-05 21:32:44 字數 2222 閱讀 3432

findfirst  是用來尋找目標目錄下的第乙個檔案,

findfirst函式在delphi幫助下的定義:

function findfirst(const path: string; attr: integer; var f: tsearchrec): integer;

其中有一句:findfirst returns 0 if a file was successfully located

也就是說,當成功找到檔案時,返回0.

findnext   則是尋找下乙個

tsearchrec 是乙個檔案資訊的紀錄,當findfirst返回searchrec時,你可以通過searchrec.name獲取檔名,以及searchrec.size獲取檔案大小等資訊。

unit   unit1;  

inte***ce  

uses  

windows,   messages,   sysutils,   classes,   graphics,   controls,   forms,   dialogs,  

db,   dbtables,   stdctrls,   dbctrls,   mask,   extctrls;  

type  

tform1   =   class(tform)  

button1:   tbutton;  

memo1:   tmemo;  

edit1:   tedit;  

procedure   button1click(sender:   tobject);  

private  

public  

end;  

var  

form1:   tform1;  

countd,countf:integer;  

implementation  

procedure   search(dir:string);  

var  

targetpath:string;  

sr:tsearchrec;  

begin  

targetpath:=extractfilepath(dir);   

if   findfirst(dir,faanyfile,sr)=0   then  

repeat  

if((sr.name<>'.')and(sr.name<>'..')    

and((filegetattr(targetpath+sr.name)and   fadirectory)<>fadirectory))   

then  

begin  

form1.memo1.lines.add(targetpath+sr.name);  

countf:=countf+1;  

end  

until   findnext(sr)<>0;  

if   findfirst(dir,faanyfile,sr)=0   then  

repeat  

if((sr.name<>'.')and(sr.name<>'..'))  

and((filegetattr(targetpath+sr.name)and   fadirectory)=fadirectory)  

then  

begin  

search(targetpath+sr.name+'\*.*');  

form1.memo1.lines.add(targetpath+sr.name);  

countd:=countd+1;  

end  

until   findnext(sr)<>0;  

end;  

procedure   tform1.button1click(sender:   tobject);  

begin  

countf:=0;  

countd:=0;  

memo1.clear;  

search(edit1.text);  

messagedlg('檔案搜尋完畢!',mtinformation,[mbok],0);  

showmessage('目錄:'+inttostr(countd)+'   檔案:'+inttostr(countf))  

end;  

end.

linux下檔案查詢工具 find

常用的檔案查詢命令有 which,locate,find 查詢二進位制數或二進位制命令,由path給出 特點 1.非實時,每天在系統上生成資料庫,通過資料庫查詢 2.模糊查詢 3.updatedb,實時查詢需要進行資料的更新,更新一般需要幾分鐘時間,所以一般是在晚上 4.查詢速度快 特點 1.實時查...

find檔案查詢

我們很多時候會忘記某個檔案在什麼位置,此時就需要進行檔案查詢。linux檔案查詢主要是使用find命令來進行查詢,find命令可以通過不同的維度來定位到某個想要查詢的檔案。find 查詢的範圍 選項 表示式 動作 使用示例如下 root oldboy find name ls 以根目錄下的所有檔案作...

檔案查詢 find

find 查詢目錄 引數 檔案名字 find usr name time.c 使用萬用字元 find usr name ime.c find usr name ime.c 代表任意個字元 代表單個字元 touch命令用於修改檔案或者目錄的時間屬性,包括訪問時間和更改時間。若檔案不存在,系統會建立乙個...