本文整理汇总了C++中FilePath::getUpDir方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePath::getUpDir方法的具体用法?C++ FilePath::getUpDir怎么用?C++ FilePath::getUpDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath::getUpDir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getApplicationDir
FileDir FileDir::getApplicationDir()
{
#ifdef WIN32
unsigned int pathSize=512;
ByteArray tmpPath;
tmpPath.resize( pathSize );
GetModuleFileName( 0, tmpPath.data(), pathSize);
FilePath tmp = tmpPath.data();
tmp = tmp.getUpDir();
//delete tmpPath;
return tmp;
#elif defined(__linux__)
char exe_path[PATH_MAX] = {0};
char * dir_path;
sprintf(exe_path, "/proc/%d/exe", getpid());
readlink(exe_path, exe_path, sizeof(exe_path));
dir_path = dirname(exe_path);
return FilePath(dir_path);
#elif defined(__APPLE__)
char exe_path[PROC_PIDPATHINFO_MAXSIZE];
int ret = proc_pidpath(getpid(), exe_path, sizeof(exe_path));
if (ret <= 0)
{
THROW("Cannot get application executable file path");
}
return FilePath(dirname(exe_path));
#endif
return FilePath( "." );
}
示例2: flattenFilename
//! flatten a path and file name for example: "/you/me/../." becomes "/you"
FilePath FilePath::flattenFilename( const FilePath& root ) const
{
std::string directory = addEndSlash().toString();
directory = StringHelper::replace( directory, "\\", "/" );
FilePath dir;
FilePath subdir;
int lastpos = 0;
std::string::size_type pos = 0;
bool lastWasRealDir=false;
while( ( pos = directory.find( '/', lastpos) ) != std::string::npos )
{
subdir = FilePath( directory.substr(lastpos, pos - lastpos + 1) );
if( subdir.toString() == "../" )
{
if (lastWasRealDir)
{
dir = dir.getUpDir();
dir = dir.getUpDir();
lastWasRealDir=( dir.toString().size()!=0);
}
else
{
dir = FilePath( dir.toString() + subdir.toString() );
lastWasRealDir=false;
}
}
else if( subdir.toString() == "/")
{
dir = root;
}
else if( subdir.toString() != "./" )
{
dir = FilePath( dir.toString() + subdir.toString() );
lastWasRealDir=true;
}
lastpos = pos + 1;
}
return dir;
}
示例3: getApplicationDir
FileDir FileDir::getApplicationDir()
{
#ifdef WIN32
unsigned int pathSize=512;
ByteArray tmpPath;
tmpPath.resize( pathSize );
GetModuleFileName( 0, tmpPath.data(), pathSize);
FilePath tmp = tmpPath.data();
tmp = tmp.getUpDir();
//delete tmpPath;
return tmp;
#elif defined(__linux__)
char exe_path[PATH_MAX] = {0};
char * dir_path;
sprintf(exe_path, "/proc/%d/exe", getpid());
readlink(exe_path, exe_path, sizeof(exe_path));
dir_path = dirname(exe_path);
return FilePath(dir_path);
#endif // __GNUC__
return FilePath( "" );
}