Visual Computing Library
Loading...
Searching...
No Matches
vcl::FileInfo Class Reference

Public Member Functions

 FileInfo (const std::string &filename)
 
bool exists () const
 
std::size_t fileSize () const
 
bool isFileBinary () const
 

Static Public Member Functions

static bool exists (const std::string &filename)
 Check if a file exists.
 
static std::size_t fileSize (const std::string &filename)
 Get the size of a file.
 
static bool isFileBinary (const std::string &filename)
 Check if a file is binary.
 
static void separateExtensionFromFileName (const std::string &fullname, std::string &rawName, std::string &extension)
 Extracts the extension of a string that contains a filename.
 
static void separateFileNameFromPath (const std::string &fullpath, std::string &path, std::string &filename)
 Extracts the filename (extension included) of a string that contains a fullpath.
 
static std::string pathWithoutFileName (const std::string &fullpath)
 Get the path of a file.
 
static std::string fileNameWithoutExtension (const std::string &fullpath)
 Get the file name without extension of a file.
 
static std::string fileNameWithExtension (const std::string &fullpath)
 Get the filename with extension of a file.
 
static std::string extension (const std::string &filename)
 Get the extension of a file.
 
static std::string addExtensionIfNeeded (const std::string &filename, const std::string &ext)
 Adds an extension to a file name if it doesn't already have it.
 

Private Attributes

std::string mFilename
 

Member Function Documentation

◆ addExtensionIfNeeded()

static std::string vcl::FileInfo::addExtensionIfNeeded ( const std::string &  filename,
const std::string &  ext 
)
inlinestatic

Adds an extension to a file name if it doesn't already have it.

Parameters
[in]filenameThe file name to add the extension to.
[in]extThe extension to add to the file name.
Returns
The file name with the extension added.

◆ exists()

static bool vcl::FileInfo::exists ( const std::string &  filename)
inlinestatic

Check if a file exists.

Parameters
[in]filenamestring containing the filename
Returns
true if the file exists, false otherwise

◆ extension()

static std::string vcl::FileInfo::extension ( const std::string &  filename)
inlinestatic

Get the extension of a file.

Example of usage:

std::string fullname = "/usr/bin/foo.sh";
//ext = ".sh"
static std::string extension(const std::string &filename)
Get the extension of a file.
Definition file_info.h:257
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Parameters
[in]filenamestring containing the filename
Returns
the extension of the file

◆ fileNameWithExtension()

static std::string vcl::FileInfo::fileNameWithExtension ( const std::string &  fullpath)
inlinestatic

Get the filename with extension of a file.

Example of usage:

std::string fullname = "/usr/bin/foo.sh";
//filename = "foo.sh"
static std::string fileNameWithExtension(const std::string &fullpath)
Get the filename with extension of a file.
Definition file_info.h:237
Parameters
[in]fullpathstring containing the full path of the file
Returns
the filename with extension of the file

◆ fileNameWithoutExtension()

static std::string vcl::FileInfo::fileNameWithoutExtension ( const std::string &  fullpath)
inlinestatic

Get the file name without extension of a file.

Example of usage:

std::string fullname = "/usr/bin/foo.sh";
//filename = "foo"
static std::string fileNameWithoutExtension(const std::string &fullpath)
Get the file name without extension of a file.
Definition file_info.h:217
Parameters
[in]fullpathstring containing the full path of the file
Returns
the filename without extension of the file

◆ fileSize()

static std::size_t vcl::FileInfo::fileSize ( const std::string &  filename)
inlinestatic

Get the size of a file.

Parameters
[in]filenamestring containing the filename
Returns
the size of the file in bytes

◆ isFileBinary()

static bool vcl::FileInfo::isFileBinary ( const std::string &  filename)
inlinestatic

Check if a file is binary.

The function checks the first 1000 bytes of the file. If a single byte is not an ASCII character (i.e., its value is greater than 127), the file is considered binary.

Parameters
[in]filenamestring containing the filename
Returns
true if the file is binary, false otherwise
Exceptions
vcl::MalformedFileExceptionif the file cannot be read

◆ pathWithoutFileName()

static std::string vcl::FileInfo::pathWithoutFileName ( const std::string &  fullpath)
inlinestatic

Get the path of a file.

Example of usage:

std::string fullname = "/usr/bin/foo.sh";
//path = "/usr/bin/"
static std::string pathWithoutFileName(const std::string &fullpath)
Get the path of a file.
Definition file_info.h:197
Parameters
[in]fullpathstring containing the full path of the file
Returns
the path of the file

◆ separateExtensionFromFileName()

static void vcl::FileInfo::separateExtensionFromFileName ( const std::string &  fullname,
std::string &  rawName,
std::string &  extension 
)
inlinestatic

Extracts the extension of a string that contains a filename.

Example of usage:

std::string fullname = "/usr/bin/foo.sh";
std::string filename, extension;
//filename = "/usr/bin/foo"
//extension = ".sh"
static void separateExtensionFromFileName(const std::string &fullname, std::string &rawName, std::string &extension)
Extracts the extension of a string that contains a filename.
Definition file_info.h:134

To separate the path from the filename, see FileInfo::separateFilenameFromPath

Parameters
[in]fullnamestring containing the filename
[out]rawNameoutput string containing the filename without the extension
[out]extensionoutput string containing the extension of the filename

◆ separateFileNameFromPath()

static void vcl::FileInfo::separateFileNameFromPath ( const std::string &  fullpath,
std::string &  path,
std::string &  filename 
)
inlinestatic

Extracts the filename (extension included) of a string that contains a fullpath.

Example of usage:

std::string fullname = "/usr/bin/foo.sh";
std::string path, filename;
//path = "/usr/bin/"
//filename = "foo.sh"
Parameters
[in]fullpathstring containing the fullpath
[out]pathoutput string containing the path of the file
[out]filenameoutput string containing the filename (extension included)

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