Esempio n. 1
0
 bool FileFinder::addSearchPath( std::string const& path )
 {
   boost::filesystem::path boostPath(path);
   bool toAdd = boost::filesystem::exists( boostPath ) && ( std::find( m_searchPaths.begin(), m_searchPaths.end(), path ) == m_searchPaths.end() );
   if ( toAdd )
   {
     m_searchPaths.push_back( path );
   }
   return toAdd;
 }
Esempio n. 2
0
//===========================================================================//
std::string getFilename(const std::string& pathname)
{
    boost::filesystem::path boostPath(pathname);

    if (boost::filesystem::is_directory(boostPath))
    {
        return "";
    }

    return boostPath.filename().string();
}
Esempio n. 3
0
//===========================================================================//
std::string getDirectory(const std::string& pathname)
{
    boost::filesystem::path boostPath(pathname);

    if (boost::filesystem::is_directory(boostPath))
    {
        return pathname;
    }

    const std::string path = boostPath.parent_path().string();
    return path.empty() ? "." : path + "/";
}
/**
 * Create all directories in path (like "mkdir -p").
 * @param file posix filename
 */
void
FsPath::createPath(const std::string &file)
{
    boost::filesystem::create_directories(boostPath(file).branch_path());
}
/**
 * Joint two paths.
 * @param dir posix filename
 * @param file posix filename
 * @return "dir/file"
 */
    std::string
FsPath::join(const std::string &dir, const std::string &file)
{
    return (boostPath(dir) / boostPath(file)).string();
}
/**
 * Returns true when file or directory exists.
 * @param file posix filename
 */
    bool
FsPath::exists(const std::string &file)
{
    return boost::filesystem::exists(boostPath(file));
}
/**
 * Get native filename.
 * @param file posix filename
 */
    std::string
FsPath::getNative(const std::string &file)
{
    return boostPath(file).native_file_string();
}