I have a fairly simple console program here to determine if a folder or file exists or not with stat:
#include <iostream>
#include <sys/stat.h>
using namespace std;
int main() {
char path[] = "myfolder/";
struct stat status;
if(stat(path,&status)==0) { cout << "Folder found." << endl; }
else { cout << "Can't find folder." << endl; }
cin.get();
return 0;
}
I also tried the version access:
#include <iostream>
#include <io.h>
using namespace std;
int main() {
char path[] = "myfolder/";
if(access(path,0)==0) { cout << "Folder found." << endl; }
else { cout << "Can't find folder." << endl; }
cin.get();
return 0;
}
None of them find my folder (which is located directly in the same directory as the program). They worked on my last compiler (by default with DevCpp). I switched to CodeBlocks and am compiling with Gnu GCC now if this helps. I'm sure this is a quick fix - can anyone help?
(Obviously, I am a noob, so if you need any other information that I forgot, let me know).
UPDATE
The problem was in the base directory. The updated work program is as follows:
#include <iostream>
#include <sys/stat.h>
using namespace std;
int main() {
cout << "Current directory: " << system("cd") << endl;
char path[] = "./bin/Release/myfolder";
struct stat status;
if(stat(path,&status)==0) { cout << "Directory found." << endl; }
else { cout << "Can't find directory." << endl; }
cin.get();
return 0;
}
OTHER UPDATE
, .