cartobase  4.5.0
carto::FileUtil Class Reference

Files and filenames portable utilities. More...

#include <cartobase/stream/fileutil.h>

Static Public Member Functions

static char separator ()
 returns '/' on Unix systems and '\' on Windows systems More...
 
*static char pathSeparator ()
 character separating paths in a list (generally in an environment variable). More...
 
static std::string basename (const std::string &)
 this is NOT conform to basename() from libgen: ::basename( "/" ) = "/", carto::FileUtil::basename( "/" ) = "", ::basename( "/usr/" ) = "usr", carto::FileUtil::basename( "/usr/" ) = "" ::basename( "." ) = ".", carto::FileUtil::basename( "." ) = "", ::basename( ".." ) = "..", carto::FileUtil::basename( ".." ) = "", More...
 
static std::string dirname (const std::string &)
 this is NOT conform to dirname() from libgen: ::dirname( "/usr/" ) = "/", carto::FileUtil::dirname( "/usr/" ) = "/usr" More...
 
static std::string fileStat (const std::string &)
 Checks file existence, type and read/write permission. More...
 
static std::string extension (const std::string &)
 returns the file extension (without the dot) More...
 
static std::string removeExtension (const std::string &)
 returns the filename without its extension More...
 
static bool isAbsPath (const std::string &path)
 true if path is an absolute path, false if it is relative More...
 
static std::string temporaryFile (const std::string &prefix, int &fd)
 opens a temporary file. More...
 
static std::string temporaryDirectory (const std::string &prefix)
 Creates a temporary directory. More...
 
static std::list< std::string > filenamesSplit (const std::string &filenames, const std::string &separator)
 interpret the filenames string as a list of filenames and split it. More...
 
static std::string uriFilename (const std::string &filein)
 It is possible to treat an URI (Uniform Resource Identifier) instead of a simple path. More...
 
static Object uriOptions (const std::string &filein)
 Extracts the options from the URI and returns them as a dictionary of strings : ( "options1" => "this", "option2" => "that" ) More...
 
static std::string uriCopyOptions (const std::string &filein)
 Extracts the options from the URI and returns them as a string : "?options1=this&option2=that". More...
 

Detailed Description

Files and filenames portable utilities.

Definition at line 46 of file fileutil.h.

Member Function Documentation

static std::string carto::FileUtil::basename ( const std::string &  )
static

this is NOT conform to basename() from libgen: ::basename( "/" ) = "/", carto::FileUtil::basename( "/" ) = "", ::basename( "/usr/" ) = "usr", carto::FileUtil::basename( "/usr/" ) = "" ::basename( "." ) = ".", carto::FileUtil::basename( "." ) = "", ::basename( ".." ) = "..", carto::FileUtil::basename( ".." ) = "",

But I think this fits better the use we may have of it...

static std::string carto::FileUtil::dirname ( const std::string &  )
static

this is NOT conform to dirname() from libgen: ::dirname( "/usr/" ) = "/", carto::FileUtil::dirname( "/usr/" ) = "/usr"

But I think this fits better the use we may have of it...

static std::string carto::FileUtil::extension ( const std::string &  )
static

returns the file extension (without the dot)

static std::list<std::string> carto::FileUtil::filenamesSplit ( const std::string &  filenames,
const std::string &  separator 
)
static

interpret the filenames string as a list of filenames and split it.

escape characters and quotes (single and double) are allowed.

static std::string carto::FileUtil::fileStat ( const std::string &  )
static

Checks file existence, type and read/write permission.

Returns
string code containing "+" if the file exists, "r" if it is readable, "w" if it is writeable, "d" if it is a directory, "x" if it is executable (so "+rw" is the normal code for a RW file)
static bool carto::FileUtil::isAbsPath ( const std::string &  path)
static

true if path is an absolute path, false if it is relative

* static char carto::FileUtil::pathSeparator ( )
static

character separating paths in a list (generally in an environment variable).

Returns
':' on Unix systems and ';' on Windows systems
static std::string carto::FileUtil::removeExtension ( const std::string &  )
static

returns the filename without its extension

static char carto::FileUtil::separator ( )
static

returns '/' on Unix systems and '\' on Windows systems

static std::string carto::FileUtil::temporaryDirectory ( const std::string &  prefix)
static

Creates a temporary directory.

static std::string carto::FileUtil::temporaryFile ( const std::string &  prefix,
int &  fd 
)
static

opens a temporary file.

Parameters
prefixis used to name the temporary file. If it is a local file (with no path), the temporary directory will be prefixed to it, otherwise the specified directory is used. A (random) generated number will be suffixed to the prefix filename, and the extension (if any) will also be appended to it. So "toto.ima" can become "/tmp/toto123456.ima".
fdwill be filled with the file descriptor of the temp file
Returns
the full name of the temporary file

On Unix, the created file doesn't have to be deleted, it is hidden (already unlinked).

On Windows, I guess the file has to be manually deleted...

static std::string carto::FileUtil::uriCopyOptions ( const std::string &  filein)
static

Extracts the options from the URI and returns them as a string : "?options1=this&option2=that".

static std::string carto::FileUtil::uriFilename ( const std::string &  filein)
static

It is possible to treat an URI (Uniform Resource Identifier) instead of a simple path.

It would have the following syntax : "/my/path/file.ext?options1=this&option2=that" Extracts the classical filename from the URI : "/my/path/file.ext"

static Object carto::FileUtil::uriOptions ( const std::string &  filein)
static

Extracts the options from the URI and returns them as a dictionary of strings : ( "options1" => "this", "option2" => "that" )


The documentation for this class was generated from the following file: