// 디렉토리인지 알아냄.
bool is_directory( const std::string & path )
{
DWORD ret = ::GetFileAttributes( path.c_str() );
if( ret == INVALID_FILE_ATTRIBUTES )
return false;
if( ret & FILE_ATTRIBUTE_DIRECTORY )
return true;
return false;
}
// 파일 경로와 관계된 모든 부모 디렉토리를 만든다.
bool dig_path( const std::string & fullPath )
{
using std::string;
string path = fullPath;
// 파일경로에서 디렉토리 경로만 얻음.
string::size_type pos = path.find_last_of( "/\\" );
if( pos != string::npos )
{
path.erase( ++pos, string::npos );
}
// 네트워크 경로 인가? 예제) "\\192.168.0.1\test"
pos = 0;
if( path.compare( 0, 2, "\\\\") == 0 )
pos = 2;
// 상위 경로를 찾아가며 디렉토리를 순서대로 만든다.
while( (pos = path.find_first_of( "/\\", pos )) != string::npos )
{
string subPath = path.substr( 0, pos++ );
if(is_directory(subPath )==false)
::CreateDirectory (subPath.c_str(), 0);
}
return true;
}
파일 경로와 관계된 모든 부모 디렉토리를 만드는 함수
2010. 11. 16. 18:42