建议你看看TWIN32FindData结构。FindFirstFile的第二个参数是这种结构的变量。包含了文件的属性、各种时间、文件大小、名称等信息。路径本来就给出来了嘛,需要的话在前面加上不就得了。
var
  MyFileName: TWIN32FindData;  if FindFirstFile('c:\*.log',myFilename)<>INVALID_HANDLE_VALUE then
  begin
    Edit1.Text := MyFileName.cFileName;
    ...
  end;

解决方案 »

  1.   

    你没有定义 你的变量myfilename
      

  2.   

    to: chinajavis(我选择 我喜欢) 
    这个结构我都看过了,不知道怎么回事。
    我用findfirstfile取一下,再用findnextfile取一下,还是第一个文件。
    要到第三个findnextfile才取到下一个文件。
    另外。如何判断子目录?解决一定另外加分。
      

  3.   

    我原来贴的贴子,其实问之前,可以搜索一下,可能以前已经有一些答案了,呵呵,希望可以给到你帮助。procedure TForm1.Button1Click(Sender: TObject);
    var
      myList:TStringList;
    begin
      try
        MyList:=TStringList.Create ;
        searchfile('c:\chenhu2',MyList);
        Listbox1.Items.AddStrings(MyList);
      finally
        Mylist.Free ;
      end;
    end;procedure TForm1.SearchFile(DestPath: String;
      NowList: TStringList);
    var
       searchrec:TSearchRec;
       ret:integer;
       NowPath:String;
    begin
      //为搜索的目录构造符合条件的形式
      if DestPath[length(DestPath)]<>'\' then begin
        NowPath:=DestPath+'\';
      end else begin
        NowPath:=DestPath;
      end;
      ret:=findfirst(NowPath+'*.*',faAnyFile,searchrec);
      while ret=0 do begin
        //如果搜索到是目录,则递归搜索
        if (searchrec.Attr and faDirectory)= faDirectory then begin
          if (SearchRec.Name <>'.') and (SearchRec.Name <>'..') then begin
            SearchFile(NowPath+SearchRec.Name,NowList);
          end;
        end else begin
          //否则加入列表中
          NowList.Add(NowPath+SearchRec.Name);
        end;
        ret:=findNext(SearchRec);
      end;
      findClose(SearchRec);
    end; 
      

  4.   

    : venne(感觉一下) 
    没办法,看来我只好用findfirst,findnext了,上次已经给过你分了,这次
    少给点:(
      

  5.   

    呵呵,我偏不信邪,用findfirstfile有很大区别吗?你试试我这个,没有你说的问题哦,而且在我看来,和上面的代码是一样的哦。procedure TForm1.SearchFile(beginPath: PChar; NowList: TStringList);
    var
      searchrec:_WIN32_FIND_DATAA;
      SearchHandle:cardinal;
      searching:LongBool;
      NowPath,AddPath:Pchar;
    begin
      GetMem(Nowpath,255);
      strcopy(NowPath,Beginpath);
      StrCat(NowPath,'*.*');
      SearchHandle:=findfirstfile(NowPath,searchrec);
      searching:=false;
      if SearchHandle<>INVALID_HANDLE_VALUE then begin
        searching:=true;
      end;
      While searching do begin
        if SearchREc.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then begin
          if (string(SearchRec.cFileName)<>'.') and (string(SearchRec.cFileName)<>'..' ) then begin
            getmem(AddPath,255);
            strcopy(addpath,beginpath);
            strcat(addpath,searchRec.cFileName);
            strcat(addpath,'\');
            searchfile(addpath,NowList);
            freemem(addpath);
          end;
        end else begin
          getmem(AddPath,255);
          strcopy(addpath,beginpath);
          strcat(addpath,searchRec.cFileName);
          NowList.Add(string(addpath));
          freemem(addpath);
        end;
        searching:=findnextfile(SearchHandle,Searchrec);
      end;
      windows.findclose(Searchhandle);
      FreeMem(Nowpath);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      MyList:TStringList;
      i:integer;
    begin
     try
      MyList:=TStringList.Create ;
      //注意在此,应该确保调用参数的正确,没有检测哦
      SearchFile('c:\chenhu2\',MyList);
      for i:=0 to Mylist.Count -1 do begin
        Listbox1.Items.Add(MyList[i]);
      end;
     finally
      MyList.Free ;
     end;
    end;