Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to check whether the folder exists or not?
Posted 26-May-11 1: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 at 26-May-11 6:30am
   
Simple and direct solution!My 5
venkatmakam at 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 at 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 at 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 at 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

  Permalink  
Comments
santosh dhanawade at 27-May-11 0:16am
   
Hey OP NEED simple solution
venkatmakam at 27-May-11 5:02am
   
passing file path as argument and checking the return value...,I think it is a simple solution :).
santosh dhanawade at 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
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 26 May 2011
Copyright © CodeProject, 1999-2014
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