To determine if a directory exists and create a directory:
test whether the dir exist cstring m_dir; if (M_dir. Right (1) == "//") m_dir = m_dir. Left (M_dir. GetLength ()-1); if (GetFileAttributes (m_dir) == file_attribute_directory) return ture; else createalldirectory (m_dir); // function createalldirectory// recursive function void Createalldirectory (Cstring dir) {if (Dir.right (1) == "//") Dir = dir.left (Dir.getlength ()-1); if (getfileattributes == file_attribute_directory) return; else if (GetFileAttributes (dir) != -1) {if (DeleteFile (dir)) // delete the fIle with the same name if (CreateDirectory (dir, null)) Return MessageBox (_t ("Can not create directory for captured pictures"), NULL,  MB_OK); } int n = dir.reversefind ('//'); Createalldirectory (Dir.left (n)); if (! CreateDirectory (Dir, null)) messagebox (_T ("Can not create directory for captured pictures "),  NULL, MB_OK); }
To determine if a file in Dir exists, it can also be accomplished by FileFind:
BOOL fileexist (CString strfilename) {CFileFind ffind; Return Ffind.findfile (strFileName); }