///////////////////////////////////////////////////////////////////////////// // Rev 11/12/2003 // // // GETLONGPATHNAME.C // ----------------- // // // Sylvain MARECHAL - sylvain.marechal1@libertysurf.fr ///////////////////////////////////////////////////////////////////////////// // // Show how to retrieve the long path name from a path // ///////////////////////////////////////////////////////////////////////////// #include #include static BOOL GetLongPathNameFromCompletePath( char * pszSource, char * pszDest ) { char * p, * p2; WIN32_FIND_DATA FindFileData; HANDLE hFind; // First test if( ! pszSource || pszSource[0] == 0 || (pszSource[1] != ':' && pszSource[2] != '\\' ) ) { return FALSE; } // Inits memcpy( pszDest, pszSource, 2 ); pszDest[2] = 0; // Skip 'drive:\' p = pszSource + 3; do { // Look for next slash p2 = strchr( p, '\\' ); if( p2 ) { // set pszSource as String Z before this slash *p2 = 0; } // Find complete name for file or sub folder hFind = FindFirstFile( pszSource, &FindFileData ); if (hFind != INVALID_HANDLE_VALUE) { // Save part of the path strcat( pszDest, "\\" ); strcat( pszDest, FindFileData.cFileName ); FindClose(hFind); } else { // Probably something is wrong ... return FALSE; } // Set old char if( p2 ) { *p2 = '\\'; p = p2+1; } } while( p2 != NULL ); // All OK return TRUE; } void main( int argc, char * argv[] ) { char szResult[MAX_PATH]; char szSource[MAX_PATH]; GetShortPathName( argv[0], szSource, MAX_PATH ); GetLongPathNameFromCompletePath( szSource, szResult ); printf( "Path ='%s'\n", szResult ); }