如何获取一个文件夹中所有文件的路径??
比如d盘下文件夹A中有文件file1,file2,file3,file4,..............如何获得这些文件的路径?我想用循环的方式获取这些文件的路径,然后对每一个文件进行处理。
比如我获得file1的路径为 c:\a\file1, 进行操作,比如StringReplace(file1),然后获取file2的路径,再进行操作StringReplace(file2), 一直到所有文件操作完为止。
请问那位大侠可提供代码或函数啊??感激不尽!

解决方案 »

  1.   

    http://hubdog.csdn.net/Recommend/rcFolder.htm
      

  2.   

    //=====================================================================
    // 函数名称: FindAll
    // 功能描述: 找指定目录下的文件
    // 参    数:  APath   : 路径名称
    //            APropty : 属性名称(*.* | *.txt)
    //            AFiles  : 文件列表
    // 返 回 值:
    // 说    明:
    //=====================================================================
    procedure FindAll(const APath: String; var AFiles: TStrings; APropty: String = '*.XML');
    var
      FPath: String;
      FS: TSearchRec;
    begin
      FPath := IncludeTrailingPathDelimiter(APath);
      if FindFirst(FPath + APropty, faAnyFile, FS) = 0 then
      begin
        if (FS.Name <> '.') and (FS.Name <> '..') then
        begin
          if (FS.Attr and faDirectory) = faDirectory then
            FindAll(FPath + FS.Name, AFiles)
          else
            AFiles.Add(UpperCase(FPath) + FS.Name);
        end;
        while FindNext(FS) = 0 do
        begin
          if (FS.Name <> '.') and (FS.Name <> '..') then
          begin
            if (FS.Attr and faDirectory) = faDirectory then
              FindAll(FPath + FS.Name, AFiles)
            else
              AFiles.Add(UpperCase(FPath) + FS.Name);
          end;
        end;
      end;
      FindClose(FS);
    end;