Verify Path Exists





-6
Date Submitted Thu. Oct. 13th, 2005 7:26 PM
Revision 1 of 1
Coder mattrmiller
Tags CPlusPlus | Path | Verify
Comments 2 comments
Verify Path Exists
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;
}

Matthew R. Miller

www.bluecreststudios.com
=================
Matthew R. Miller

http://bluecreststudios.com
http://www.codeandcoffee.com

Comments

Comments There are ways and means
Fri. Sep. 22nd, 2006 12:28 AM    Scripter sehrgut
Comments Poorly named
Fri. Jul. 21st, 2006 1:14 AM    Beginner hello2usir

Voting