9
9

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > fileIO > サブフォルダに含まれる全ファイル数取得の実装

Last updated at Posted at 2015-09-09
動作確認
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/09)
  • TEST\DATA1
    • abc.txt
    • cde.txt
  • TEST\DATA2
    • fgh.txt
    • ijk.txt
    • lmn.txt

のようなフォルダ構成の時に、全ファイル数(=5)を取得したい。

以下のように実装した。

#include <IOUtils.hpp> // for TDirectory.XXX
...
static int s_getTotalFileNumbers(String targetDir)
{
    if (DirectoryExists(targetDir) == false) {
        return 0;
    }

    String filePattern = L"*.*";
    TStringDynArray fileList;
    TSearchOption option = TSearchOption::soAllDirectories; // all folders

    fileList = TDirectory::GetFiles(targetDir, filePattern, option);
    return fileList.Length; 
}

以下のように使うと5が取得できる。

int numFiles = s_getTotalFileNumbers(L"C:\\TEST");
9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9