I'm working on a project and I need to check if a folder exists or not using Turbo C++ (yeah yeah, I get it, it's an ancient IDE that is no longer supported and there are a tonne of other free compilers for Windows but I need to use Turbo for the project as that's what my school wants).
I know how to create a folder if it doesn't exist using mkdir() function which would return 0 on success.
As one can notice, the code works perfectly fine on the first run and creates a folder called FOLDER. But let's say I run the code again, it shows the ERROR message which in this case is not what I want. Therefore, I need something to check that if FOLDER doesn't exist already, then create it or else if it does exist than run the 'else' part of my code.Code:enum bool { FALSE = 0 , TRUE = 1 }; typedef bool bool; void main (void) { int ERROR_IN_CREATING_FOLDER = mkdir( "C:\\TURBOC3\\BIN\\FOLDER" ); if ( ERROR_IN_CREATING_FOLDER == TRUE ) { cout<<endl<<" ERROR! FOLDER COULD NOT BE CREATED"<<endl <<endl<<" (Press any key to exit)"; getch(); exit(0); } else { // Do the stuff I need to do } }
Something of this sort:
I looked up for solutions on Google but none of them are viable on TURBO as they require windows.h.Code:if ( ERROR_IN_CREATING_FOLDER == TRUE && Does_Folder_Exist == FALSE ) { // ERROR } else { // Do the stuff I need to do }