0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2016-02-24
動作確認
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/09)

http://qiita.com/7of9/items/2210b09d068fea5c5090
の機能追加版。

日付期間のフィルタを入れたい。

Unit1.cpp
static int __fastcall s_getTotalFileNumbers_dateRange(String targetDir, TDateTime fromDt, TDateTime toDt)
{
    if (DirectoryExists(targetDir) == false) {
        return 0;
    }

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

    fileList = TDirectory::GetFiles(targetDir, filePattern, option);

    int filecnt = fileList.Length;
    TDateTime fildt;
    int skipcnt = 0;
    for(int idx = 0; idx < filecnt; idx++) {
    	fildt = TFile::GetLastWriteTime(fileList[idx]);
    	if (fildt < fromDt || fildt > toDt) {
    		skipcnt++;
    	}
    }
    return (filecnt - skipcnt);
}

日付の名前づけで to / from / tilなどの考慮した記事があり、それに自分もコメントしたのだが、その記事を検索でぱっと見つけられない。

delphiでの実装ではfunction()を使ってフィルタ処理を定義する例がある。ただし、DateStop, DateStartの定義の仕方がしっくりこない。
http://www.experts-exchange.com/questions/25103365/TDirectory-GetFiles-with-DateTime-filter.html

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?