我想知道在指定目录下,文件名含关键字"M64"的文件是否存在,并且获取这个文件名

解决方案 »

  1.   

    FindFirstFindNextFindClose(sr);
    就搞定了
      

  2.   

    新得到该文件夹下所有子文件夹的名字。然后一个判断是不是含有 'M64'。获得子文件夹名的方法:procedure   FindDirUnder(strDir:   string;   IncludeSelf:   boolean;   var   DirList:   TStringList);   
          //   得到StrDir目录下的子目录以DirList返回   
      procedure   FindFileUnder(strDir,   ExtName:   string;   var   FileList:   TStringList);   
          //   得到StrDir目录下的所有以ExtFile('.pas')为扩展名的文件   以FileList返回   
        
        
        
      procedure   FindDirUnder(strDir:   string;   IncludeSelf:   boolean;   var   DirList:   TStringList);   
      var   
          SRec:   TSearchRec;   
          retval:   Integer;   
      begin   
          DirList.Clear;   
          retval   :=   FindFirst(strDir+'\*.*',faDirectory,sRec);   
          try   
              while   retval   =   0   do   
              begin   
                  if   (SRec.Attr   and   faDirectory)   <>   0   then   
                      if   (Srec.Name   =   '.')   or   (Srec.Name   =   '..')   then   
                      begin   
                          if   IncludeSelf   then   
                              DirList.Add(Srec.Name)   
                      end   else   
                          DirList.Add(Srec.Name);   
                  retval   :=   FindNext(SRec);   
              end;   
          finally   
              FindClose(SRec);   
          end;   
      end;   
        
      procedure   FindFileUnder(strDir,ExtName:string;var   FileList:TStringList);   
      var   
          SRec:   TSearchRec;   
          retval:   Integer;   
      begin   
          FileList.Clear;   
          retval   :=   FindFirst(strDir+'\'+ExtName,faAnyFile,sRec);   
          try   
              while   retval   =   0   do   
              begin   
                  if   (SRec.Attr   and   faDirectory)   =   0   then   
                      FileList.Add(Srec.Name);   
                  retval   :=   FindNext(SRec);   
              end;   
          finally   
              FindClose(SRec);   
          end;   
      end;