존재하지 않는 폴더를 만들려고합니다. Windows를 사용하고 있으며 다른 플랫폼에서 작동하는 코드에 관심이 없습니다.폴더가 있는지 및 폴더를 만드는 방법을 찾는 방법은 무엇입니까?
신경 쓰지 마라. 해결책을 찾았습니다. 나는 방금 포용 문제가 있었어. 대답은 다음과 같습니다.
#include <io.h> // For access().
#include <sys/types.h> // For stat().
#include <sys/stat.h> // For stat().
#include <iostream>
#include <string>
using namespace std;
string strPath;
cout << "Enter directory to check: ";
cin >> strPath;
if (access(strPath.c_str(), 0) == 0)
{
struct stat status;
stat(strPath.c_str(), &status);
if (status.st_mode & S_IFDIR)
{
cout << "The directory exists." << endl;
}
else
{
cout << "The path you entered is a file." << endl;
}
}
else
{
cout << "Path doesn't exist." << endl;
}
심각하게? 초기 질문에는 코드 조각이 없었으며이 코드는 질문을 반영하지 않습니다. "내 코드는 뭐가 잘못되었나?" –
수정 사항을 답변으로 게시하고 수락해야합니다. –
답변이나 의견으로 게시하지 못했습니다. – Sara