PDA

View Full Version : سوال: جستجو ی فایل ها در حافظه



kamran_14
جمعه 26 آذر 1389, 14:47 عصر
سلام
خسته نباشید
می شه در مورد برنامه ی پایین توضیح دهید؟
ممنون.
برنامه ای بنویسید که کار جستجو در حافظه ی کامپیوتر و پیدا کردن فایل مورد نظر و نمایش اطلاعات را انجام دهد

procedure TForm1.FormActivate(Sender: TObject);
begin
c.Clear;
if directoryexists('C:\') then
c.Items.Add('C:\');
if directoryexists('D:\') then
c.Items.Add('D:\');
if directoryexists('E:\') then
c.Items.Add('E:\');
if directoryexists('F:\') then
c.Items.Add('F:\');
if directoryexists('G:\') then
c.Items.Add('G:\');
if directoryexists('H:\') then
c.Items.Add('H:\');
if directoryexists('I:\') then
c.Items.Add('I:\');
if directoryexists('J:\') then
c.Items.Add('J:\');
if directoryexists('K:\') then
c.Items.Add('K:\');
if directoryexists('L:\') then
c.Items.Add('L:\');
if directoryexists('M:\') then
c.Items.Add('M:\');
if directoryexists('N:\') then
c.Items.Add('N:\');
if directoryexists('O:\') then
c.Items.Add('O:\');
if directoryexists('P:\') then
c.Items.Add('P:\');
if directoryexists('Q:\') then
c.Items.Add('Q:\');
if directoryexists('R:\') then
c.Items.Add('R:\');
if directoryexists('S:\') then
c.Items.Add('S:\');
if directoryexists('T:\') then
c.Items.Add('T:\');
if directoryexists('U:\') then
c.Items.Add('U:\');
if directoryexists('V:\') then
c.Items.Add('V:\');
if directoryexists('W:\') then
c.Items.Add('W:\');
if directoryexists('X:\') then
c.Items.Add('X:\');
if directoryexists('Y:\') then
c.Items.Add('Y:\');
if directoryexists('Z:\') then
c.Items.Add('Z:\');
c.ItemIndex:=0;
end;
تا اینجا بررسی می کنه که نام درایو شماچیست تا در COMBOBOX نشان دهد.

procedure tform1.F_S(const pn,fn:string;const id:boolean);
var
rec:tsearchrec;
path:string;
begin
path:=includetrailingbackslash(pn);
if findfirst(path+fn,faanyfile,rec)=0 then
try
try
repeat
form1.l.Items.Add(path+rec.Name);
until findnext(rec)<>0;
except
showmessage('error');
end;
finally
findclose(rec);
end;
if not id then exit;
if findfirst(path+'*.*',fadirectory,rec)=0 then
try
repeat
if ((rec.Attr and fadirectory)<>0) and (rec.Name<>'.') and (rec.Name<>'..') then
F_S(path+rec.Name,fn,true);
until findnext(rec)<>0;
finally
findclose(rec);
end;
end;
من این کد FILESEARCH را تقریبا فهمیدم ولی شرط

if ((rec.Attr and fadirectory)<>0) and (rec.Name<>'.') and (rec.Name<>'..') then
را نفهمیدم می شه این شرط را توضیح بدهید .
ممنون.

tdkhakpur
جمعه 26 آذر 1389, 22:15 عصر
خب شرط بررسی میکنه که داده مورد نظر پیدا شده فقط دایرکتوری باشه نه فایل.
در ضمن بررسی علامت . و همچنین .. نشان میده که دایرکتوری از این نقطه شروع میشه و این بررسی هم انجام شده تا این داده نیز جزو دایرکتوری به حساب نیاید.

Felony
شنبه 27 آذر 1389, 07:52 صبح
به جای اون همه if از یک حلقه استفاده کنید ، مثلا :


var
Drive: Char;
begin
for Drive:= 'A' to 'Z' do
if directoryexists(Drive+':') then
c.Items.Add(Drive+':\');
end;