cartobase  5.0.5
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 windowsFilename (const std::string &filename)
 Replaces slashes with backslashes characters. More...
 
static std::string linuxFilename (const std::string &filename)
 Replaces backslashes with slashes characters on Windows OS on other OS, leaves filename unchanged. 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 53 of file fileutil.h.

Member Function Documentation

◆ basename()

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...

◆ dirname()

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...

◆ extension()

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

returns the file extension (without the dot)

◆ filenamesSplit()

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.

◆ fileStat()

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)

◆ isAbsPath()

static bool carto::FileUtil::isAbsPath ( const std::string &  path)
static

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

◆ linuxFilename()

static std::string carto::FileUtil::linuxFilename ( const std::string &  filename)
static

Replaces backslashes with slashes characters on Windows OS on other OS, leaves filename unchanged.

◆ pathSeparator()

* 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

◆ removeExtension()

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

returns the filename without its extension

◆ separator()

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

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

◆ temporaryDirectory()

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

Creates a temporary directory.

◆ temporaryFile()

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...

◆ uriCopyOptions()

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".

◆ uriFilename()

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"

◆ uriOptions()

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" )

◆ windowsFilename()

static std::string carto::FileUtil::windowsFilename ( const std::string &  filename)
static

Replaces slashes with backslashes characters.


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