掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
フォルダ内のファイルの数を知るには? (ID:8857)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
皆さんお忙しいようなので、 FindFirst, FindNextを使うと取得できます。 function GetFilesCount(const Path: String): Integer; var Res: Integer; SearchRec: TSearchRec; Attri: Integer; Count: Integer; S: String; begin Result := 0; Count := 0; // Pathの最後が'\'でない場合、'\'を加える = 重要 // IncludeTrailingPathDelimiter()がないVersionでは // IncludeTrailingBackslash()を使用 // それもないversionでは、IsPathDelimiter()でチェックし、 // S := Path + '\' S := IncludeTrailingPathDelimiter(Path); Res := FindFirst(S + '*.*', faAnyFile, SearchRec); try try while Res = 0 do begin Attri := SearchRec.Attr; if (Attri <> faDirectory) then Inc(Count); Res := FindNext(SearchRec); end; Result := Count; except Showmessage('ファイル数の取得に失敗しました。'); end; finally FindClose(SearchRec); end; end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.