MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / Path_FindParentDirectoryRecursively

Function Path_FindParentDirectoryRecursively

samples/shared/pathtools.cpp:505–527  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: helper to find a directory upstream from a given path -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

503// Purpose: helper to find a directory upstream from a given path
504//-----------------------------------------------------------------------------
505std::string Path_FindParentDirectoryRecursively( const std::string &strStartDirectory, const std::string &strDirectoryName )
506{
507 std::string strFoundPath = "";
508 std::string strCurrentPath = Path_FixSlashes( strStartDirectory );
509 if ( strCurrentPath.length() == 0 )
510 return "";
511
512 bool bExists = Path_Exists( strCurrentPath );
513 std::string strCurrentDirectoryName = Path_StripDirectory( strCurrentPath );
514 if ( bExists && stricmp( strCurrentDirectoryName.c_str(), strDirectoryName.c_str() ) == 0 )
515 return strCurrentPath;
516
517 while( bExists && strCurrentPath.length() != 0 )
518 {
519 strCurrentPath = Path_StripFilename( strCurrentPath );
520 strCurrentDirectoryName = Path_StripDirectory( strCurrentPath );
521 bExists = Path_Exists( strCurrentPath );
522 if ( bExists && stricmp( strCurrentDirectoryName.c_str(), strDirectoryName.c_str() ) == 0 )
523 return strCurrentPath;
524 }
525
526 return "";
527}
528
529
530//-----------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 6

Path_FixSlashesFunction · 0.70
Path_ExistsFunction · 0.70
Path_StripDirectoryFunction · 0.70
stricmpFunction · 0.70
Path_StripFilenameFunction · 0.70
lengthMethod · 0.45

Tested by

no test coverage detected