读取目录下文件能否设置多重过滤条件(50分)

  • 主题发起人 YuanGuo2001
  • 开始时间
Y

YuanGuo2001

Unregistered / Unconfirmed
GUEST, unregistred user!
下面的代码只能查找目录下扩展名为'*.gif'的文件,请问怎么设置才能查找
符合多重过滤条件,譬如我要查找扩展名只要符合'*.gif'和'*.bmp'都显示,
怎么实现,我用filter:='*.gif'|'*.bmp'不行的.谢谢
var
SR:TSearchRec;
filter:string;
end;
begin
filter:='*.gif';
findfirst('c:/winnt/system32/'+Filter,$ff,SR)=0
end;
 
filter:='gif file(*.gif)|*.gif|bmp file(*.bmp)|*.bmp';
 
不行的呀
 
对不起,看错了,那个东东还没来得及研究!
 
对了,不要叫我都两次哦,呵呵
在线等候---------------------
 
我是这样做的
findfirst('c:/winnt/system32/'+Filter-1,$ff,SR);
findnext(...);
close(sr);
...
findfirst('c:/winnt/system32/'+Filter-N,$ff,SR);
findnext(...);
close(sr);
 
那么N个过滤,就得都N次了???
 

我找到一个函数和cookie 的Expire 有关。

但它需要Cookie 的 URL 表示,
如果知道Cookie 的 URL表示,就应该能解读它的Expire.
Function GetUrlCacheEntryInfo(sUrlName:pchar;
lpCacheEntryInfo:pointer;
lpdwCacheEntryInfoBufferSize:pinteger)
:Boolean;stdcall;external 'wininet.dll'
name 'GetUrlCacheEntryInfoA';

 
偶也在寻找这个问题的解决办法,仍在探索中。
折中的办法是采用通配符“*.*”,再在循环和递归中用if判断每一个文件。但这样
效率比较差。
我发现Windows本身的文件查找功能,可以用“*.jpg, *.bmp”这样的办法,达到一
次查找多种文件。注意,它绝对不是分别查找两次,可以从状态条中看到。
 
把第一次的结果存入 StringList,后面几次都在该 StringList 里面进行,很快的。

 
to beta:你说得结果是指搜索到文件吧
那后面的后面几次都在该 StringList 里面进行,可否讲讲,我不太理解,谢谢
 
没有人知道??
 
'*.gif';'*.bmp'
这样不行吗?
 
自己处理不也很好办!!!!!!!

procedure TForm1.Button2Click(Sender: TObject);
var
SR:TSearchRec;
filter:TStrings;
s:string;
begin
filter:=TStringList.create;
filter.add('BMP');
filter.add('SCR');
filter.add('EXE');
if FindFirst('c:/windows/system/*.*', $3f, sr)=0 then
begin
while FindNext(sr)=0 do
begin
s:=trim(UpperCase(extractFileExt(sr.Name)));
if length(s)=0 then continue;
if s[1]='.' then s:=copy(s,2,length(s)-1);
if filter.IndexOf(s)>=0 then showmessage(sr.Name);
end;
FindClose(sr);
end;
filter.free;
end;
 
jsxjd:思路独特,呵呵

我老是在考虑'c:/windows/system'+Filter中的Filter的组成。

多谢乐,高手
 
顶部