Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to check whether the folder exists or not?
Posted

This will tell you if a FILE or DIRECTORY exists or not...

BOOL FolderExists(CString strFolderName)
{       
  return GetFileAttributes(strFolderName) != INVALID_FILE_ATTRIBUTES;   
}


Hope this helps...
 
Share this answer
 
Hey Simply try this,
if(!CreateDirectory(FileName))
{
   MessageBox("Directory is already exist!");
}
 
Share this answer
 
Comments
hakz.code 26-May-11 6:30am    
Simple and direct solution!My 5
But CreateDirectory will create the directory if it not exists.So it is not useful i think.Any way i countered down vote :-)
ShilpiP 26-May-11 7:04am    
See the OP previous question http://www.codeproject.com/Questions/201937/How-to-create-folders-and-sub-folders-in-vcplusplu.aspx

Actually he wants to create a directory but before creating he wants to check that directory is exist or not.
I did not aware of that question.But for checking the existence of directory i think CreateDirectory is not a good solution,since we have some more alternates.:-)
ShilpiP 26-May-11 8:21am    
Yes I know that's why send you the link :).
 
Share this answer
 
Comments
[no name] 27-May-11 0:16am    
Hey OP NEED simple solution
passing file path as argument and checking the return value...,I think it is a simple solution :).
[no name] 27-May-11 0:16am    
Sorry for down vote

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900