EDN Admin
Well-known member
I have problem when I try to check if directory exist on VS 2010. I use CLR Console Application. This is code I used :
bool folderexists( char * foldername ){<br/>
<span style="white-spacere if ( _access( foldername, 0 ) == 0 ){ <br/>
<span style="white-spacere struct stat status;<br/>
<span style="white-spacere stat( foldername, &status );<br/>
<br/>
<span style="white-spacere if ( status.st_mode & S_IFDIR ){ <br/>
<span style="white-spacere cout << "nThe directory exists." << endl;<br/>
<span style="white-spacere return true;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere else{<br/>
<span style="white-spacere cout << "nThe path you entered is a file." << endl;<br/>
<span style="white-spacere return false;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<span style="white-spacere else{<br/>
<span style="white-spacere cout << "nPath doesnt exist." << endl;<br/>
<span style="white-spacere return false;<br/>
<span style="white-spacere }<br/>
}
The code return false and print " The path you entered is a file ", although if the input is directory. But if I try the code on VS2005, it work successfully and return
true , print " The directory exists ".<br/>
What must I do so that the results are correct? Any body can help fix my problem.
View the full article
bool folderexists( char * foldername ){<br/>
<span style="white-spacere if ( _access( foldername, 0 ) == 0 ){ <br/>
<span style="white-spacere struct stat status;<br/>
<span style="white-spacere stat( foldername, &status );<br/>
<br/>
<span style="white-spacere if ( status.st_mode & S_IFDIR ){ <br/>
<span style="white-spacere cout << "nThe directory exists." << endl;<br/>
<span style="white-spacere return true;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere else{<br/>
<span style="white-spacere cout << "nThe path you entered is a file." << endl;<br/>
<span style="white-spacere return false;<br/>
<span style="white-spacere }<br/>
<span style="white-spacere }<br/>
<span style="white-spacere else{<br/>
<span style="white-spacere cout << "nPath doesnt exist." << endl;<br/>
<span style="white-spacere return false;<br/>
<span style="white-spacere }<br/>
}
The code return false and print " The path you entered is a file ", although if the input is directory. But if I try the code on VS2005, it work successfully and return
true , print " The directory exists ".<br/>
What must I do so that the results are correct? Any body can help fix my problem.
View the full article