procedure TForm1.GetFileList1(AStrings: TStrings; ASourFile: string);
var
 sour_path,sour_file: string;
    TmpList:TStringList;
    FileRec:TSearchrec;
begin   sour_path:=ExtractFilePath(ASourFile);
   sour_file:=ExtractFileName(ASourFile);   if not DirectoryExists(sour_path) then
   begin
     AStrings.Clear;
     exit;
   end;   TmpList:=TStringList.Create;
   TmpList.Clear;   if FindFirst(sour_path+sour_file,faAnyfile,FileRec) = 0 then
   repeat
      if ((FileRec.Attr and faDirectory) = 0) then
         begin
           TmpList.Add(sour_path+FileRec.Name)
         end;
   until FindNext(FileRec)<>0;   SysUtils.FindClose(FileRec);   AStrings.Assign(TmpList);   TmpList.Free;
   label3.Caption:=sour_path;
   label2.Caption:=sour_FILE;end;调用代码
procedure TForm1.Button6Click(Sender: TObject);
var
path2:string;
begin
path2:=PATH+'*.tif';
edit1.Text:=path2;
GetFileList1(ListBox1.items,'F:\123\*.TIF');end;问题:在调用GETFILELIST1时,如果'F:\123\*.TIF'换成path2,则提取不到文件路径,为什么?

解决方案 »

  1.   

    如果'F:\123\*.TIF'换成path2,则提取不到文件路径
    GetFileList1(ListBox1.items,'F:\123\*.TIF');
    GetFileList1(ListBox1.items,path2);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    调用GetFileList1(ListBox1.items,path2)前,showmessage(path2)看看你的path2是什么?估计是少个\
      

  2.   

    PATH2的值确实是F:\123\*.TIF,在EDIT1.TEXT里面可以看到!STEP OVER到if FindFirst(sour_path+sour_file,faAnyfile,FileRec) = 0 then
    直接跳转了!郁闷
      

  3.   

    他的 edit1.Text:=path2; 就是这个用途
      

  4.   

    我测试了下,没问题:
    procedure TForm1.GetFileList1(AStrings: TStrings; ASourFile: string);
    var sour_path,sour_file: string;
        TmpList:TStringList;
        FileRec:TSearchrec;
    begin
      sour_path:=ExtractFilePath(ASourFile);
      sour_file:=ExtractFileName(ASourFile);
      if not DirectoryExists(sour_path) then begin
        AStrings.Clear;
        exit;
      end;
      TmpList:=TStringList.Create;
      TmpList.Clear;
      if FindFirst(sour_path+sour_file,faAnyfile,FileRec) = 0 then
      repeat
        if ((FileRec.Attr and faDirectory) = 0) then  begin
          TmpList.Add(sour_path+FileRec.Name)
        end;
      until FindNext(FileRec)<>0;
      SysUtils.FindClose(FileRec);
      AStrings.Assign(TmpList);
      TmpList.Free;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    var path2,PATH:string;
    begin
      if OpenDialog1.Execute then begin
        PATH:=ExtractFilePath(OpenDialog1.FileName);
        path2:=PATH+'*.rar';
        GetFileList1(ListBox1.items,path2);
      end;
    end;
      

  5.   

    估计 F:\123\*.TIF 这里,要么 没F:\123\这个路径,要么没 TIF 扩展名的文件。
      

  6.   

    谢谢大家,问题找到了,菜鸟级别的问题,哎!
    path:=ExtractFilePath(Application.ExeName); 
    if   SelectDirectory( ' ', ' ',Path)   then
      begin 
        if   path[length(path)] <> '\'   then   path:=path+ '\';
             Edit1.Text:=path;
         end;
    我用的API开的文件夹,结果多了一个空格,奇怪的是TRIM也没用!谢谢大家