Click here to Skip to main content
12,395,352 members (67,678 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VC8.0 C++
How to check whether the folder exists or not?
Posted 26-May-11 0:15am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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...
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hey Simply try this,
if(!CreateDirectory(FileName))
{
   MessageBox("Directory is already exist!");
}
  Permalink  
Comments
HarishTheLearner 26-May-11 6:30am
   
Simple and direct solution!My 5
venkatmakam 26-May-11 6:54am
   
But CreateDirectory will create the directory if it not exists.So it is not useful i think.Any way i countered down vote :-)
SP 24 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.
venkatmakam 26-May-11 8:12am
   
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.:-)
SP 24 26-May-11 8:21am
   
Yes I know that's why send you the link :).
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Comments
santosh dhanawade 27-May-11 0:16am
   
Hey OP NEED simple solution
venkatmakam 27-May-11 5:02am
   
passing file path as argument and checking the return value...,I think it is a simple solution :).
santosh dhanawade 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 26 May 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100