First of all, this is done in netbeans on a virtual lunix 32 bit machine. Here are the two functions I have written...
Here is the working version of my function. It correctly returns true when a folder is a file.
EDIT: Nevermind; is also eratic and sometimes returns everything or nothing as a folder. BUT the commented out code still effects the answer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
bool isFolder(char * filename)
{
struct stat t;
lstat(filename, &t);
if (S_ISDIR(t.st_mode))
returntrue;
elsereturnfalse;
struct stat st;
lstat(filename, &st);
return (S_ISDIR(st.st_mode));
}
Now I present you the non-functional version, that almost never works, except sometimes in very rare cases. And when the file is . or ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14
bool isFolder(char * filename)
{
struct stat t;
lstat(filename, &t);
if (S_ISDIR(t.st_mode))
returntrue;
elsereturnfalse;
// struct stat st;
// lstat(filename, &st);
// return (S_ISDIR(st.st_mode));
}
If you look carefully you'll notice that the only difference is that I commented out the code that is never called. I have tested and made sure that it is never called. However, it will not work unless this part is un-commented. Pardon my french.. but what the shit? How am I to program in a language that doesn't actually.. well.. WORK
The function is intended to tell me if a folder is a directory or a file. The problem is that the output is different depending on if the code that is never run is commented out or not. That's a core logical problem.