最終更新日時(UTC):
が更新

履歴 編集

function
<filesystem>

std::filesystem::path::has_stem(C++17)

bool has_stem() const;

概要

パスに、拡張子を除いたファイル名が含まれているか判定する。

戻り値

return !stem().empty();

POSIXベースシステムでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path ps[] = {
    "/foo/bar.txt",    // ファイル名を含むパス
    "/foo/bar.tar.gz", // ファイル名に複数のドットが含まれるパス
    "/foo/",           // ディレクトリパス
    "/foo/.",          // カレントディレクトリ
    "..",              // 親ディレクトリ
  };

  std::cout << std::boolalpha;
  for (const fs::path& p : ps) {
    std::cout << p << " : " << p.has_stem() << std::endl;
  }
}

出力

"/foo/bar.txt" : true
"/foo/bar.tar.gz" : true
"/foo/" : false
"/foo/." : true
".." : true

Windowsでの例

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path ps[] = {
    "C:/foo/bar.txt",    // ファイル名を含むパス
    "C:/foo/bar.tar.gz", // ファイル名に複数のドットが含まれるパス
    "C:/foo/",           // ディレクトリパス
    "C:/foo/.",          // カレントディレクトリ
    "..",                // 親ディレクトリ
  };

  std::cout << std::boolalpha;
  for (const fs::path& p : ps) {
    std::cout << p << " : " << p.has_stem() << std::endl;
  }
}

出力

"C:/foo/bar.txt" : true
"C:/foo/bar.tar.gz" : true
"C:/foo/" : false
"C:/foo/." : true
".." : true

バージョン

言語

  • C++17

処理系