掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
サブフォルダも検索するには? (ID:10295)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
土日は Res がつきにくいですね。 procedure ListUpFiles(Path, Ext: String; var List: TStringList); var SearchRec: TSearchRec; SearchRes: integer; Attri: Integer; begin Ext := AnsiLowerCase(Ext); // Pathの最後が'\'でない場合、'\'を加える = 重要 // Delphi5以上では、 // Path := IncludeTrailingBackslash(Path); の1行でよい if not IsPathDelimiter(Path, Length(Path)) then Path := Path + '\'; SearchRes := FindFirst(Path + '*', faAnyFile, SearchRec); try while SearchRes = 0 do begin Attri := SearchRec.Attr and faDirectory; if (Attri = faDirectory) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then ListUpFiles(Path + SearchRec.Name, Ext, List) // 再起処理 else // ターゲットファイルをリストアップ if AnsiLowerCase(ExtractFileExt(SearchRec.Name)) = Ext then List.Add(Path + SearchRec.Name); SearchRes := FindNext(SearchRec); end; finally FindClose(SearchRec); end; end; // Demo procedure TForm1.Button1Click(Sender: TObject); var i: Integer; List: TStringList; Path: String; begin Path := '???????????'; List := TStringList.Create; ListUpFiles(Path, '.txt', List); Label1.Caption := '検索終了; 集計数' + IntToStr(List.Count); for i := 0 to List.Count - 1 do Memo1.Lines.Add(List.Strings[i]); end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.