problem check if directory exists on native C++ VS2010

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
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-space:pre if ( _access( foldername, 0 ) == 0 ){ <br/>
<span style="white-space:pre struct stat status;<br/>
<span style="white-space:pre stat( foldername, &status );<br/>
<br/>
<span style="white-space:pre if ( status.st_mode & S_IFDIR ){ <br/>
<span style="white-space:pre cout << "nThe directory exists." << endl;<br/>
<span style="white-space:pre return true;<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre else{<br/>
<span style="white-space:pre cout << "nThe path you entered is a file." << endl;<br/>
<span style="white-space:pre return false;<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre }<br/>
<span style="white-space:pre else{<br/>
<span style="white-space:pre cout << "nPath doesnt exist." << endl;<br/>
<span style="white-space:pre return false;<br/>
<span style="white-space:pre }<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
 
Back
Top