Delphi Drawers

ファイル一覧を取得

指定したフォルダのファイル一覧を取得します。
サブフォルダの中身も抽出します。

function fnGetFilePathListByFolderPath(
          strPath:string;
          bSubFolder:boolean;
          iOutPutMode:integer
          ):TStringList;
var
  newStringList:TStringList;
begin
  newStringList:=TStringList.create;
  newStringList.Clear;
  strPath:= IncludeTrailingPathDelimiter(strPath);
  fnGetFilePathListByFolderPath := fnPrivateGetFilePathListByFolderPath(newStringList,strPath,strPath,bSubFolder,iOutPutMode);
end;
function fnPrivateGetFilePathListByFolderPath(
          theList: TStringList;
          strParentPath:string;
          strCurrentPath:string;
          bSubFolder:boolean;
          iOutPutMode:integer
          ):TStringList;
var
  iRC: integer;
  srTemp : TSearchRec;
  strFilePath: string;
begin
  strCurrentPath:= IncludeTrailingPathDelimiter(strCurrentPath);
  iRC := FindFirst(strCurrentPath + '*.*', faAnyfile, srTemp);
  try
    {$IFDEF WIN32}
    while iRC = 0 do
    {$else}
    while iRC<>-18 do
    {$ENDIF}
    begin
      if (srTemp.Name <> '..') and (srTemp.Name <> '.') then begin
        strFilePath := strCurrentPath + srTemp.Name;
        if (srTemp.Attr and faDirectory > 0) then begin
          strFilePath:= IncludeTrailingPathDelimiter(strFilePath);
          if bSubFolder then begin
            TheList := fnPrivateGetFilePathListByFolderPath(TheList,strParentPath,strFilePath,bSubFolder,iOutPutMode);
          end;
        end else begin
          case (iOutPutMode) of
          0:theList.Add(StringReplace(strFilePath,strParentPath,'',[rfReplaceAll]));
          1:theList.Add(strFilePath);
          else
          end;
        end;
      end;
      iRC := FindNext(srTemp);
    end;
  finally
    sysutils.FindClose(srTemp);
  end;
  fnPrivateGetFilePathListByFolderPath := theList;
end;
Copyright © 2006 Hikijishi All Rights Reserved.
[] [delphi][0.00158309936523438]