如何得到指定目录下的所有文件?(不包括目录)

解决方案 »

  1.   

    function GetFiles(APath: string;AExtFileName: string = '*.*';
        AllowReturnFullPath: Boolean = False): TStrings;
    {取得指定目录下的所有文件名称}
    var
      SR:TSearchRec;
      i:Integer;
      tFilePath: string;
    begin
      Result:= TStringList.Create;
      if RightStr(APath,1) <> '\' then
        APath:= APath + '\';
      i:=FindFirst(APath + AExtfileName, faAnyFile, SR);
      if AllowReturnFullPath then
        tFilePath:= APath
      else
        tFilePath:= '';
      while i = 0 do
      begin
        Result.Add(tFilePath + SR.Name);
        i:= FindNext(SR);
      end;
      FindClose(SR);
    end;
    我做的一个函数,第一个参数是目录,第二个是扩展名,第三个是否返回带目录的文件名
      

  2.   

    用FindFirst, FindNext, FindClose (DELPHI有example)
      

  3.   

    lanchong(懒虫): faAnyFile包含了目录。换成 0 就对了。--
    http://www.agui.googlepages.com
    mailto: agui.cn(a)gmail.com