Top / Programming / C++Builder / 一時ファイル用のディレクトリのパスを取得する

一時ファイル用のディレクトリのパスを取得する

IOUtilsユニットのTPath::GetTempPath()関数を使用します。

#include <IOUtils.hpp>
UnicodeString path = TPath::GetTempPath();

IOUtilsユニットの使えない古いバージョンのC++Builderで一時ファイル用のディレクトリのパスを取得するには、GetTempPath() APIを使用します。

AnsiString GetTempPath()
{
  char tmpPath[MAX_PATH];
  if (::GetTempPath(MAX_PATH, tmpPath) == 0)
  {
    //失敗した時の処理
    throw Exception("Cannot get temporary direcotry.");
  }
  return AnsiString(tmpPath);
}

更新履歴