Clarisse 5.0 SP8 SDK  5.0.5.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Static Public Member Functions | Friends | List of all members
SysFilesystem Class Reference

Classes

struct  FileInformations
 

Static Public Member Functions

static CoreString get_folder (const CoreBasicString &full_path)
 Get the folder of the specified path.
 
static CoreString get_filename (const CoreBasicString &full_path)
 Get the filename from the specified path.
 
static CoreString get_file_extension (const CoreBasicString &full_path)
 Get the file extension (without dot) of the specified path.
 
static CoreString get_filename_without_extension (const CoreBasicString &full_path)
 Get the filename without the extension from the specified path.
 
static bool check_file_extension (const CoreBasicString &filename, const CoreBasicString &extension, bool case_sensitive=false)
 Returns true if the given filename's extension is equal to the given extension.
 
static bool check_file_extension (const CoreBasicString &filename, const CoreBasicArray< CoreString > &extensions, bool case_sensitive=false)
 Returns true if the given filename's extension is equal to one of the given extensions.
 
static bool check_files_extension (const CoreBasicArray< CoreString > &filenames, const CoreBasicString &extension, bool case_sensitive=false)
 Returns true if all the given filename's extensions are equal to the given extension.
 
static bool check_files_extension (const CoreBasicArray< CoreString > &filenames, const CoreBasicArray< CoreString > &extensions, bool case_sensitive=false)
 Returns true if all the given filename's extensions are equal to one of the given extensions.
 
static CoreString get_full_file_path (const CoreBasicString &filename)
 Get the absolute path of the specified file or folder path.
 
static CoreString get_absolute_path (const CoreBasicString &path)
 Get the absolute path of the specified file or folder path.
 
static bool folder_exists (const CoreBasicString &folder_path)
 Query if the specified folder exists.
 
static bool is_file_writable (const CoreBasicString &file_path)
 Query if the specified file is writable.
 
static bool is_folder_writable (const CoreBasicString &folder_path)
 Query if the specified folder is writable.
 
static bool file_exists (const CoreBasicString &file_path)
 Query if the specified file exists.
 
static bool files_exist (const CoreBasicArray< CoreString > &file_paths)
 Query if all paths in the given file path list exist.
 
static bool is_relative (const CoreBasicString &full_path)
 Query if the specified path is relative (not absolute).
 
static bool is_absolute (const CoreBasicString &full_path)
 Query if the specified path is absolute (not relative).
 
static unsigned long long get_folder_size (const CoreBasicString &folder_path)
 Get the total size of all files in the specified folder.
 
static unsigned long long get_file_size (const CoreBasicString &file_path)
 Get the size of the specified file.
 
static CoreString get_file_owner (const CoreBasicString &full_path)
 Return the owner name of the specified file or folder path.
 
static CoreString get_folder_separator ()
 Get the default folder separator string "/".
 
static CoreVector< CoreStringget_folders (const CoreBasicString &folder_path, bool hidden_folders=true, CoreVector< FileInformations > *informations=0)
 Get all the sub-folders in the specified folder.
 
static CoreVector< CoreStringget_files (const CoreBasicString &path, bool hidden_files=true, CoreVector< FileInformations > *informations=0)
 Get all the sub-files in the specified folder.
 
static bool get_file_information (const CoreBasicString &file_path, FileInformations *informations)
 Get the file information of the specified file.
 
static CoreVector< CoreStringget_volumes ()
 Get all volumes. On Unix returns only "/".
 
static bool get_volume_name (const CoreBasicString &path, CoreString &name)
 Get the name of the specified volume path.
 
static void format_path (CoreString &path)
 Format path.
 
static void format_path_to_platform (CoreString &path)
 Format a path to the current platform's path format.
 
static void windows_path_to_unix (CoreString &path)
 Convert a Windows style path to Unix style.
 
static void make_windows_path (CoreString &path)
 Convert a path (Unix-style or not) to Windows style (using "\").
 
static bool remove_file (const CoreBasicString &file)
 Remove the specified file.
 
static bool rename_file (const CoreBasicString &full_path, const CoreBasicString &new_full_path)
 Rename the specified file.
 
static bool create_folder (const CoreBasicString &folder, bool recursive=false)
 Create the folder at the specified path.
 
static bool create_unique_folder (CoreString &folder, const CoreBasicString &parent_folder, const CoreBasicString &folder_name_prefix={}, bool recursive=false)
 
static bool remove_folder (const CoreBasicString &folder, bool recursive=false)
 Remove the specified folder.
 
static bool rename_folder (const CoreBasicString &full_path, const CoreBasicString &new_full_path)
 Rename the specified folder.
 
static bool get_file_modification_time (const CoreBasicString &file_path, time_t &result)
 Get file modification time.
 
static bool get_file_creation_time (const CoreBasicString &file_path, time_t &result)
 Get file creation time.
 
static bool get_file_access_time (const CoreBasicString &file_path, time_t &result)
 Get file access time.
 
static bool is_valid_folder (const CoreBasicString &path)
 Query if the specified path is a valid folder path.
 

Friends

class SysFile
 
class SysFileTools
 
class SysFilesystemTests
 

Detailed Description

Utility class with OS independent file system functions.


Class Documentation

struct SysFilesystem::FileInformations
Class Members
time_t creation_time
CoreString file_name
unsigned long long file_size
time_t modification_time

Member Function Documentation

bool SysFilesystem::check_file_extension ( const CoreBasicString filename,
const CoreBasicString extension,
bool  case_sensitive = false 
)
static

Returns true if the given filename's extension is equal to the given extension.

Parameters
filenameFilename to test.
extensionExtension (without the point) to compare to.
case_sensitiveIf true, the extension test is case sensitive.
Returns
true if the filename extension is valid; false otherwise.
bool SysFilesystem::check_file_extension ( const CoreBasicString filename,
const CoreBasicArray< CoreString > &  extensions,
bool  case_sensitive = false 
)
static

Returns true if the given filename's extension is equal to one of the given extensions.

Parameters
filenameFilename to test.
extensionsList of extensions (without the point) to compare to.
case_sensitiveIf true, the extension test is case sensitive.
Returns
true if the filename extension is valid; false otherwise.
bool SysFilesystem::check_files_extension ( const CoreBasicArray< CoreString > &  filenames,
const CoreBasicString extension,
bool  case_sensitive = false 
)
static

Returns true if all the given filename's extensions are equal to the given extension.

Parameters
filenamesList of filenames to test.
extensionExtension (without the point) to compare to.
case_sensitiveIf true, the extension test is case sensitive.
Returns
true if all the filename's extension are valid; false if at least one filename's extension differs or if the filename list is empty.
bool SysFilesystem::check_files_extension ( const CoreBasicArray< CoreString > &  filenames,
const CoreBasicArray< CoreString > &  extensions,
bool  case_sensitive = false 
)
static

Returns true if all the given filename's extensions are equal to one of the given extensions.

Parameters
filenamesList of filenames to test.
extensionsList of extensions (without the point) to compare to.
case_sensitiveIf true, the extension test is case sensitive.
Returns
true if all the filename's extension are valid; false if at least one filename's extension differs or if the filename list is empty.
bool SysFilesystem::create_folder ( const CoreBasicString folder,
bool  recursive = false 
)
static

Create the folder at the specified path.

Parameters
folderFolder path to create.
recursiveIf true, intermediary missing parent folders will be created. If false, all parent folders must already exist.
Returns
true if succeeded.
bool SysFilesystem::create_unique_folder ( CoreString folder,
const CoreBasicString parent_folder,
const CoreBasicString folder_name_prefix = {},
bool  recursive = false 
)
static

Create a folder with a unique name based on a UUID.

Example:

  • parent folder: "/tmp/subdir" (assuming "tmp" exists and "subdir" doesn't)
  • prefix: "foo_"
  • recursive: true
  • created folder(s): "/tmp/subdir/foo_8553613c-6141-552a-5787-c6051f3d0691"
Remarks
This function does not attempt to create a new random name if the first try failed.
Parameters
folderOutput path of the created folder, on success. Unchanged on failure.
parent_folderParent folder where the new unique folder will be created. Must exist but can contain intermediate non-existing sub-folders if used with recursive = true.
folder_name_prefixOptional folder name prefix, added before the generated UUID.
recursiveOptional flag to create all intermediate parent folders recursively.
Returns
true if the folder was created successfully, false otherwise.
bool SysFilesystem::files_exist ( const CoreBasicArray< CoreString > &  file_paths)
static

Query if all paths in the given file path list exist.

Parameters
file_pathsFile path list.
Returns
true if all paths exist; false if the list is empty or if at least one file doesn't exist.
void SysFilesystem::format_path ( CoreString path)
static

Format path.

  • Replaces "\" with "/".
  • Replaces "/./" with "/".
Parameters
[in,out]pathPath to format.
CoreString SysFilesystem::get_absolute_path ( const CoreBasicString path)
static

Get the absolute path of the specified file or folder path.

The returned path is resolved and does not involve "." or "..".

Platform specific behaviors:

  • Windows:
    • links are not resolved;
    • the returned path uses Windows path format;
  • Unix: symbolic links are resolved.
Parameters
pathFile or folder path to be resolved. Can be relative or absolute. Clarisse variables are not replaced.
Returns
Absolute path on success. Empty string if path is not found.
bool SysFilesystem::get_file_access_time ( const CoreBasicString file_path,
time_t &  result 
)
static

Get file access time.

Parameters
[in]file_pathFile path.
[out]resultFile access time.
Returns
true if succeeded.
bool SysFilesystem::get_file_creation_time ( const CoreBasicString file_path,
time_t &  result 
)
static

Get file creation time.

Parameters
[in]file_pathFile path.
[out]resultFile creation time.
Returns
true if succeeded.
CoreString SysFilesystem::get_file_extension ( const CoreBasicString full_path)
static

Get the file extension (without dot) of the specified path.

Example: "/root/tmp/log.tmp" will return "tmp".

bool SysFilesystem::get_file_modification_time ( const CoreBasicString file_path,
time_t &  result 
)
static

Get file modification time.

Parameters
[in]file_pathFile path.
[out]resultFile modification time.
Returns
true if succeeded.
CoreString SysFilesystem::get_file_owner ( const CoreBasicString full_path)
static

Return the owner name of the specified file or folder path.

Parameters
full_pathPath to evaluate.
Returns
The owner name on success, an empty string on failure.
unsigned long long SysFilesystem::get_file_size ( const CoreBasicString file_path)
static

Get the size of the specified file.

Parameters
file_pathFile path. On Unix, the path must use '/' exclusively
Returns
File size in bytes.
CoreString SysFilesystem::get_filename ( const CoreBasicString full_path)
static

Get the filename from the specified path.

Example: "/root/tmp/log.tmp" will return "log.tmp"

CoreString SysFilesystem::get_filename_without_extension ( const CoreBasicString full_path)
static

Get the filename without the extension from the specified path.

Example: "/root/tmp/log.tmp" will return "log"

CoreVector< CoreString > SysFilesystem::get_files ( const CoreBasicString folder_path,
bool  hidden_files = true,
CoreVector< FileInformations > *  informations = 0 
)
static

Get all the sub-files in the specified folder.

Parameters
[in]hidden_filesIf true, hidden sub-files will be returned too.
[out]informationsFile information of the sub-files.
Returns
List of sub-files (non-recursive).
CoreString SysFilesystem::get_folder ( const CoreBasicString full_path)
static

Get the folder of the specified path.

Example: "/root/tmp/log.tmp" will return "/root/tmp"

unsigned long long SysFilesystem::get_folder_size ( const CoreBasicString folder_path)
static

Get the total size of all files in the specified folder.

Warning
Computed size is not recursive and does not count sub-folders size recursively.
Parameters
folder_pathFolder path. On Unix, the path must use '/' exclusively.
Returns
Folder size in bytes.
CoreVector< CoreString > SysFilesystem::get_folders ( const CoreBasicString folder_path,
bool  hidden_folders = true,
CoreVector< FileInformations > *  informations = 0 
)
static

Get all the sub-folders in the specified folder.

Parameters
[in]hidden_foldersIf true, hidden sub-folders will be returned too.
[out]informationsFile information of the sub-folders.
Returns
List of sub-folders (non-recursive).
CoreString SysFilesystem::get_full_file_path ( const CoreBasicString filename)
static

Get the absolute path of the specified file or folder path.

The returned path is resolved and does not involve "." or "..".Platform specific behaviors:

  • Windows:
    • links are not resolved;
    • the returned path uses Windows path format;
  • Unix: symbolic links are resolved.
Parameters
pathFile or folder path to be resolved. Can be relative or absolute. Clarisse variables are not replaced.
Returns
Absolute path on success. Empty string if path is not found.

Deprecated:
See SysFilesystem::get_absolute_path
bool SysFilesystem::get_volume_name ( const CoreBasicString path,
CoreString name 
)
static

Get the name of the specified volume path.

This function is relevant only on Windows. On Unix there are no volumes and this function always returns false.

Warning
Windows: removable drives aren't not supported and the function will always return false.
Parameters
pathA valid volume root path with a trailing back-slash. Examples: "C:\" or "\\MyServer\MyShare\".
nameOutput string containing the volume name (e.g. "System") on success. Note that the volume name can be empty if no name was assigned to it.
Returns
true if succeeded to get the volume name, false otherwise.
bool SysFilesystem::is_absolute ( const CoreBasicString full_path)
static

Query if the specified path is absolute (not relative).

See Also
is_relative
bool SysFilesystem::is_relative ( const CoreBasicString full_path)
static

Query if the specified path is relative (not absolute).

A path is considered relative if:

  • it is empty
  • it doesn't start with "/" or "\"
  • it doesn't contain ":"
See Also
is_absolute
void SysFilesystem::make_windows_path ( CoreString path)
static

Convert a path (Unix-style or not) to Windows style (using "\").

Example: "/tmp/log.tmp" will return "\tmp\log.tmp".

bool SysFilesystem::remove_file ( const CoreBasicString file)
static

Remove the specified file.

Returns
true if succeeded.
bool SysFilesystem::remove_folder ( const CoreBasicString folder,
bool  recursive = false 
)
static

Remove the specified folder.

Parameters
folderFolder to remove.
recursiveIf true, all sub-folders and files are removed recursively. If false, the folder will be removed only if empty.
Returns
true if succeeded.
bool SysFilesystem::rename_file ( const CoreBasicString full_path,
const CoreBasicString new_full_path 
)
static

Rename the specified file.

Returns
true if succeeded.
bool SysFilesystem::rename_folder ( const CoreBasicString full_path,
const CoreBasicString new_full_path 
)
static

Rename the specified folder.

Returns
true if succeeded
void SysFilesystem::windows_path_to_unix ( CoreString path)
static

Convert a Windows style path to Unix style.

Example: "C:\tmp\log.tmp" will return "C:/tmp/log.tmp"