folder viewer

Hey guys... i need a little bit knowledge of yours, below is just a part of my program and in this stage it works fine when you input the correct name of the folder you want to open. but if you input a folder name that not found in the desktop, he will open "my documents" instead. i want to stop the operation when the input folder name are not found in the desktop. any idea how to do this? thanks...

1
2
3
4
cout << "Folder name: ";
getline(cin, folderName);
string openFolder = "start explorer %USERPROFILE%\\desktop\\" +folderName;
system(openFolder.c_str());
Last edited on
make an if statement that checks if the directory exists. If it doesn't then have it say a message that asks if they want the program to restart.
I did like this but it still the same happen.


1
2
3
4
5
6
7
8
9
10
        cout << "Folder name: ";
	getline(cin, folderName);
	string openFolder = "start explorer %USERPROFILE%\\desktop\\" +folderName;
  	DWORD F_Exist = GetFileAttributesA(openFolder.c_str());
   if(F_Exist == INVALID_FILE_ATTRIBUTES) {
         cout <<"Folder not found"; 
        }
   if(F_Exist & FILE_ATTRIBUTE_DIRECTORY) {
         system(openFolder.c_str());
        }
Last edited on
i don' know much about the "FILE_ATTRIBUTE_DIRECTORY" but i guess it's a Constant that holds an Integer value.

so your second if is something like "F_Exist" has some value > 0 AND (??) "FILE_ATTRIBUTE_DIRECTORY" has some value > 0 ....
The second is trivial and will always deliver the same true/false ...

It should look like

1
2
3
4
5
6
7
DWORD F_Exist = GetFileAttributesA(openFolder.c_str());
   if(F_Exist == INVALID_FILE_ATTRIBUTES) {
         cout <<"Folder not found"; 
        }else if(F_Exist == FILE_ATTRIBUTE_DIRECTORY){
....
}


... well maybe. I have not too much knowledge in that windows world, and maybe "&" is something really sophisticated that does somthing i don't know.
But it seems like your program always enters the second "IF" statement ... so its woth trying with an else ...

Last edited on
Topic archived. No new replies allowed.