如何实现文件过滤??请教高手我现在有个题目,要求搜索一些文件,比如最简单的txt文件,通过输入一些关键字就可以知道这些文件中有哪些是包含这些内容的??(不需要打开这些文件)
另外,如果要进行扩展,比如是html,doc,zip,rar文件,甚至pdf文件,如何实现??
请给出具体方案,我是个菜鸟
我的email:[email protected]
欢迎高手程序预览图请看下列网址。
http://bbs.2ccc.com/attachments/wonder80_200453184622.jpg

解决方案 »

  1.   

    看不懂.是不是使用文件搜索后,再一个个打开再搜索关键字?如果是:搜索函数findfirst和findnext,里面有设类型搜索属性、类型的。下面是“超级猛料”的内容。
    procedure findall(disk,path: String; var fileresult: Tstrings); 
    varfpath: String;fs: TsearchRec;beginfpath:=disk+path+'\*.*'; // <----------这里变为 *.exe ,*.txt 就是过滤啦。if findfirst(fpath,faAnyFile,fs)=0 thenbeginif (fs.Name<>'.')and(fs.Name<>'..') thenif (fs.Attr and faDirectory)=faDirectory thenfindall(disk,path+'\'+fs.Name,fileresult)elsefileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');while findnext(fs)=0 dobeginif (fs.Name<>'.')and(fs.Name<>'..') thenif (fs.Attr and faDirectory)=faDirectory thenfindall(disk,path+'\'+fs.Name,fileresult)elsefileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');end;end;findclose(fs);end;procedure DoSearchFile(Path: string; Files: TStrings = nil);varInfo: TSearchRec;procedure ProcessAFile(FileName: string);beginif Assigned(PnlPanel) thenPnlPanel.Caption := FileName;Label2.Caption := FileName;end;function IsDir: Boolean;beginwith Info doResult := (Name <> '.') and (Name <> '..') and ((attr and fadirectory) = fadirectory);end;function IsFile: Boolean;beginResult := not ((Info.Attr and faDirectory) = faDirectory);end;beginPath := IncludeTrailingBackslash(Path);tryif FindFirst(Path + '*.*', faAnyFile, Info) = 0 thenif IsFile thenProcessAFile(Path + Info.Name)else if IsDir then DoSearchFile(Path + Info.Name);while FindNext(Info) = 0 dobeginif IsDir thenDoSearchFile(Path + Info.Name)else if IsFile thenProcessAFile(Path + Info.Name);Application.ProcessMessages;if QuitFlag then Break;Sleep(100);end;finallyFindClose(Info);end;end;
      

  2.   

    不打开文件?有难度!Window是禁止磁盘直接读写的。
    一般都是打开文件,全文搜索,只是不把文件显示出来给你看罢了。
      

  3.   

    现在我想解决一些最简单的文件,如txt,html文件,请求帮忙