rabbitfoot530's diary

読んだ本と、プログラムに関することのメモです。好きな言語は、C++, Python, Golang, TypeScript。数学・物理・学習理論も好きです。

ファイル/ディレクトリの存在確認

 ファイル/ディレクトリが存在してるかどうかの確認。

#include <sys/stat.h>

int main() {
  struct stat st;
  const char* file = "exist_test.cpp";
  int ret = stat(file, &st);
  if (0 == ret) {
    std::cout << "Exist!" << std::endl;
  }
  else {
    std::cout << "Not Exist!" << std::endl;
  }

  return 0;
}