targetpath:=extractfilepath('c:\temp\');{分解出目标路径名}
      findresult:=findfirst(dir,faanyfile,sr);
      while findresult=0 do
            begin
                if (sr.Attr and faDirectory)=0 then
                begin                   
                    if lowercase(extractfileext(sr.Name))='.jpg'then
                    begin
                      sum:=sum+1;
                      label3.Caption:='源文件名:'+sr.Name+'   改为:s'+inttostr(sum)+'.jpg';
                      self.Update;
                      RenameFile(targetpath+sr.name,targetpath+'s'+inttostr(sum)+edit3.text);
                    end ;
                 end;
                 findresult:=findnext(sr);
                 showmessage(inttostr(findresult));///应该返回0,但是返回18,这个目录里面很多Jpg文件呢?怎么就找到一个呢?
            end;
          findclose(sr);

解决方案 »

  1.   

    那个dir='c:\temp\a001.jpg',该目录下有100个jpg文件。
      

  2.   

    procedure TForm1.FindAll(AFilePath: String; var fileresult: Tstrings);
    var
      fpath:  String;
      fs:   TsearchRec;
    begin
      fpath:=AFilePath+'\*.*';
      if   FindFirst(fpath,faAnyFile,fs)=0   then   //Delphi中的FindFirst函数可以得到一个文件的属性记录
      begin
        if (fs.Name<>'.')and(fs.Name<>'..')   then
        begin
          if  (fs.Attr  and  faDirectory)=faDirectory   then  FindAll(AFilePath+'\'+fs.Name,fileresult)
          else fileresult.add(AFilePath+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
        end;
        while findnext(fs)=0   do
        begin
        if (fs.Name<>'.')and(fs.Name<>'..')   then
          if (fs.Attr   and   faDirectory)=faDirectory   then Findall(AFilePath+'\'+fs.Name,fileresult)
          else  begin
    //        if LowerCase(ExtractFileExt(fs.Name))='.csv' then//这里筛选的文件后缀名
            fileresult.add(AFilePath+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');
          end;
        end;
      end;
      Findclose(fs);
    end;
      

  3.   

    findfirst(dir,faanyfile,sr); 
    dir应该是'c:\temp\*.jpg'你指定一个文件名,当然只能取得它一个了!
      

  4.   

    FilesList := TStringList.Create;//调用
      try
        findall('E:\csv',FilesList);
        ListBox2.Items.Assign(FilesList);
        Caption := 'Files found: ' + IntToStr(FilesList.Count);
      finally
        FilesList.Free;
      end;  
      

  5.   

    用windows.FindNextFile,TWin32FindData的cFileName,再辨别后缀为JPG的档,再存入STRINGLIST里,然后按STRINGLIST的COUNT总数再一个一个改名,反正档名都在STRINGLIST里面.