Link to home
Start Free TrialLog in
Avatar of tariq6000
tariq6000

asked on

create directory

if we want to create directory
we write:

BOOL create= CreateDirectory(m_pcFolderName,NULL);

But if directory already exist at destination
how can we check this.
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To expand on what JKR has said you can do:



#define FILE_DIRECTORY 0x10
#define NO_EXIST 0xFFFFFFFF

int folderExist( char *folder)
{
      DWORD fAttr = GetFileAttributes(folder);
      if (fAttr == NO_EXIST)
            return 0; /* return 0 if nothing exists */
      else if ( fAttr & FILE_DIRECTORY )
            return 1; /* return 1 for directory that exists */
      else
            return 2; /* return 2 for file */

}
That does not mak any difference - if either a directory or file with the same name is already there, the creation will fail, that's why I omitted that.
>>That does not mak any difference

I know,I didnt consider my post 'for points' anyway, I was just point out that you can explicitly check for a folder.
... and regarding that, you are absolutely right ;o)