关于一个文件搜索的小程序(100分)

  • 主题发起人 superdyp2002
  • 开始时间
S

superdyp2002

Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现这样一个功能:<br>文件名的全名格式如下:aaabbbcccdddeee.exe<br>文件的命名由以上5个部分组合成。<br>就有5个关键字可让选择:如 或者选择aaa or bbb or ccc or ddd or eee。关键字可以有<br>一个、两个或以上。如果实现文件的查找?就是如果使用通配符的问题了?如果只选择aaa<br>和ddd。。那中间的bbbccc如何用通配符表示?不然关键字就成aaaddd了。这是不会搜索到<br>什么结果的。。谢谢指点!!
 
参考:http://www.delphibbs.com/delphibbs/dispq.asp?lid=1313570<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br>&nbsp; SR:TSearchRec;<br>&nbsp; filter:TStrings;<br>&nbsp; s:string;<br>begin<br>&nbsp; filter:=TStringList.create;<br>&nbsp; filter.add('BMP');<br>&nbsp; filter.add('SCR');<br>&nbsp; filter.add('EXE');<br>&nbsp; if FindFirst('c:/windows/system/*.*', $3f, sr)=0 &nbsp;then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp; while FindNext(sr)=0 &nbsp;do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; s:=trim(UpperCase(extractFileExt(sr.Name)));<br>&nbsp; &nbsp; &nbsp; &nbsp; if length(s)=0 then continue;<br>&nbsp; &nbsp; &nbsp; &nbsp; if s[1]='.' then s:=copy(s,2,length(s)-1);<br>&nbsp; &nbsp; &nbsp; &nbsp; if filter.IndexOf(s)&gt;=0 then &nbsp;showmessage(sr.Name);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; FindClose(sr);<br>&nbsp; end;<br>&nbsp; filter.free;<br>end;<br>
 
刚才试了一下aaa*bbb的不行的。jsxjd的还没试。不过有点复杂对我来说。呵呵
 
对了。jsxjd的方法是用于文件的后缀的。我这是文件名的。不一样的。是要实现文件名的多重过滤??
 
类似的。稍微改一下不就行了。
 
请问jsxjd:'c:/windows/system/*.*', $3f, sr中的$3f参数表示什么意思?
 
filter.IndexOf(s)&gt;=0这个过滤好像是这样进行的:取文件的后缀名,<br>然后与filter.add(‘s1’)、filter.add(‘s2’)、filter.add(‘s3’)中的过滤字<br>进行过滤,如果后缀名等于s1.则显示文件名。如果没等于s1。则进行s2的比较。如果后缀<br>名等于s2。则显示。类似如此。我现在要实现的功能是这样的。如果取到一个文件,如果<br>其中包含s1,则接着看是否包含s2。如果包含s2。则接着比较是否包含s3。只有三个过<br>滤字都存在于这个文件名中时。才显示。请问这要如果修改以上的语句。十分感谢。
 
怎么没有人理会?真的没办法了。求教中....
 
顶部