DWORD VerifyPathExists(LPCTSTR pszPathName) { if (pszPathName == NULL) { return 0; } // Declare variablees TCHAR szPath[MAX_PATH]; lstrcpy(szPath, pszPathName); // Find and skip the first entry of '\\' character, that separates drive letter from the rest of the path LPTSTR psz = _tcschr(szPath, _T('\\')); if (psz == NULL) { return 0; } psz++; // Sequentially increase length of the path, while checking it on existance for (;;) { // -- Find the name of a directory psz = _tcschr(psz, _T('\\')); if (psz == NULL) { break; } // -- Temporarily substitute '\\' character with end of line character *psz = 0; // -- Creater the directory if it does not exist if (GetFileAttributes(szPath) == 0xFFFFFFFF) { if (!CreateDirectory(szPath, NULL)) { return GetLastError(); } } // -- Restore '\\' character and move ahead *psz++ = _T('\\'); } if (GetFileAttributes(szPath) == 0xFFFFFFFF) { if (!CreateDirectory(szPath, NULL)) { return GetLastError(); } } return 0; }