TSDuck v3.40-4163
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

File system and file path features (in addition to std::filesystem). More...

Collaboration diagram for File system:

Classes

class  ts::FileNameGenerator
 Generate file names based on counter or dates and time. More...
 
class  ts::PolledFile
 Description of a polled file. More...
 
class  ts::PollFiles
 A class to poll files for modifications. More...
 
class  ts::PollFilesListener
 Interface for classes listening for file modification. More...
 

Functions

UString ts::AbsoluteFilePath (const UString &path, const UString &base=UString())
 Build the absolute form of a file path.
 
UString ts::BaseName (const UString &path, const UString &suffix=UString())
 Return the base file name of a file path ("dir/foo.bar" => "foo.bar").
 
UString ts::CleanupFilePath (const UString &path)
 Cleanup a file path.
 
UString ts::DirectoryName (const UString &path)
 Return the directory name of a file path ("dir/foo.bar" => "dir").
 
template<class CONTAINER >
bool ts::ExpandWildcard (CONTAINER &container, const UString &pattern)
 Get all files matching a specified wildcard pattern.
 
template<class CONTAINER >
bool ts::ExpandWildcardAndAppend (CONTAINER &container, const UString &pattern)
 Get all files matching a specified wildcard pattern and append them into a container.
 
Time ts::GetFileModificationTimeLocal (const UString &path)
 Get the local time of the last modification of a file.
 
Time ts::GetFileModificationTimeUTC (const UString &path)
 Get the UTC time of the last modification of a file.
 
bool ts::IsAbsoluteFilePath (const UString &path)
 Check if a file path is absolute (starting at a root of a file system).
 
UString ts::RelativeFilePath (const UString &path, const UString &base=UString(), CaseSensitivity caseSensitivity=FILE_SYSTEM_CASE_SENSITVITY, bool portableSlashes=false)
 Build a relative form of a file path, relative to a base directory.
 
UString ts::SearchConfigurationFile (const UString &fileName)
 Search a configuration file.
 
UString ts::SearchExecutableFile (const UString &fileName, const UString &pathName=PATH_ENVIRONMENT_VARIABLE)
 Search an executable file.
 
template<class CONTAINER >
bool ts::SearchWildcard (CONTAINER &container, const UString &root, const UString &pattern, size_t max_levels=64, bool skip_symlinks=true)
 Search all files matching a specified wildcard pattern in a directory tree.
 
template<class CONTAINER >
bool ts::SearchWildcardAndAppend (CONTAINER &container, const UString &root, const UString &pattern, size_t max_levels=64, bool skip_symlinks=true)
 Search all files matching a specified wildcard pattern in a directory tree and append them into a container.
 
fs::path ts::TempFile (const UString &suffix=u".tmp")
 Return the name of a unique temporary file.
 
UString ts::UserConfigurationFileName (const UString &fileName, const UString &winFileName=UString())
 Build the name of a user-specific configuration file.
 
fs::path ts::UserHomeDirectory ()
 Get the current user's home directory.
 
UString ts::VernacularFilePath (const UString &path)
 Return a "vernacular" version of a file path.
 

Variables

constexpr const UCharts::DEFAULT_CSV_SEPARATOR = u","
 Default separator in CSV (comma-separated values) format.
 
constexpr const UCharts::EXECUTABLE_FILE_SUFFIX = platform - specific(".exe", "")
 Executable file suffix.
 
constexpr CaseSensitivity ts::FILE_SYSTEM_CASE_SENSITVITY = platform-specific
 Case-sensitivity of the names in the file system.
 
constexpr const UCharts::SHARED_LIBRARY_SUFFIX = platform - specific(".dll", ".so", ".dylib")
 File name extension of shared library file names (".so" on Linux, '.dylib" on macOS, ".dll" on Windows).
 

Detailed Description

File system and file path features (in addition to std::filesystem).

Function Documentation

◆ VernacularFilePath()

UString ts::VernacularFilePath ( const UString path)

Return a "vernacular" version of a file path.

Parameters
[in]pathA file path.
Returns
A copy of path where all '/' and '\' have been translated into the local directory separator.

◆ IsAbsoluteFilePath()

bool ts::IsAbsoluteFilePath ( const UString path)

Check if a file path is absolute (starting at a root of a file system).

Parameters
[in]pathA file path.
Returns
True if path is an absolute file path.

◆ AbsoluteFilePath()

UString ts::AbsoluteFilePath ( const UString path,
const UString base = UString() 
)

Build the absolute form of a file path.

Parameters
[in]pathA file path.
[in]baseThe base directory to use if path is a relative file path. By default, when base is empty, the current working directory is used.
Returns
The absolute form of path after cleanup.

◆ RelativeFilePath()

UString ts::RelativeFilePath ( const UString path,
const UString base = UString(),
CaseSensitivity  caseSensitivity = FILE_SYSTEM_CASE_SENSITVITY,
bool  portableSlashes = false 
)

Build a relative form of a file path, relative to a base directory.

Parameters
[in]pathA file path.
[in]baseThe base directory to use. By default, when base is empty, the current working directory is used.
[in]caseSensitivityCase sensitivity of file names comparison. By default, use the local file system case sensitivity.
[in]portableSlashesIf true, the relative path contains forward slashes ('/'), even on Windows. The resulting path can be used in relative URL's for instance.
Returns
The absolute form of path after cleanup.

◆ CleanupFilePath()

UString ts::CleanupFilePath ( const UString path)

Cleanup a file path.

Parameters
[in]pathA file path.
Returns
The clean form of path. Double slashes are removed. Forms such as "." or ".." are reduced.

◆ DirectoryName()

UString ts::DirectoryName ( const UString path)

Return the directory name of a file path ("dir/foo.bar" => "dir").

Parameters
[in]pathA file path.
Returns
The directory name of path ("dir/foo.bar" => "dir").

◆ BaseName()

UString ts::BaseName ( const UString path,
const UString suffix = UString() 
)

Return the base file name of a file path ("dir/foo.bar" => "foo.bar").

Parameters
[in]pathA file path.
[in]suffixAn optional file suffix. If path ends in suffix, the suffix is removed.
Returns
The base file name of path ("dir/foo.bar" => "foo.bar").

◆ UserHomeDirectory()

fs::path ts::UserHomeDirectory ( )

Get the current user's home directory.

Returns
The full path of the current user's home directory.
Exceptions
ts::ExceptionIn case of operating system error.

◆ TempFile()

fs::path ts::TempFile ( const UString suffix = u".tmp")

Return the name of a unique temporary file.

Parameters
[in]suffixAn optional suffix to add to the file name.
Returns
A unique temporary file name.

◆ GetFileModificationTimeLocal()

Time ts::GetFileModificationTimeLocal ( const UString path)

Get the local time of the last modification of a file.

Parameters
[in]pathA file path.
Returns
Last modification time or Time::Epoch in case of error.

◆ GetFileModificationTimeUTC()

Time ts::GetFileModificationTimeUTC ( const UString path)

Get the UTC time of the last modification of a file.

Parameters
[in]pathA file path.
Returns
Last modification time or Time::Epoch in case of error.

◆ ExpandWildcardAndAppend()

template<class CONTAINER >
bool ts::ExpandWildcardAndAppend ( CONTAINER &  container,
const UString pattern 
)

Get all files matching a specified wildcard pattern and append them into a container.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[in,out]containerA container of UString receiving the the names of all files matching the wildcard. The names are appended at the end of the existing content of the container.
[in]patternA file path pattern with wildcards. The syntax of the wildcards is system-dependent.
Returns
True on success, false on error. Note that finding no file matching the pattern is not an error, it simply return no file name.

◆ ExpandWildcard()

template<class CONTAINER >
bool ts::ExpandWildcard ( CONTAINER &  container,
const UString pattern 
)
inline

Get all files matching a specified wildcard pattern.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[out]containerA container of UString receiving the the names of all files matching the wildcard.
[in]patternA file path pattern with wildcards. The syntax of the wildcards is system-dependent.
Returns
True on success, false on error. Note that finding no file matching the pattern is not an error, it simply return no file name.

◆ SearchWildcardAndAppend()

template<class CONTAINER >
bool ts::SearchWildcardAndAppend ( CONTAINER &  container,
const UString root,
const UString pattern,
size_t  max_levels = 64,
bool  skip_symlinks = true 
)

Search all files matching a specified wildcard pattern in a directory tree and append them into a container.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[in,out]containerA container of UString receiving the the names of all files matching the wildcard. The names are appended at the end of the existing content of the container.
[in]rootRoot directory into which the files are searched.
[in]patternA file path pattern with wildcards. The syntax of the wildcards is system-dependent.
[in]max_levelsMaximum number of directory recursions. Since some operating systems allow loops in the file system, it is a good idea to set some limit to avoid infinite recursion.
[in]skip_symlinksIf true, do not recurse through symbolic links to directories.
Returns
True on success, false on error. Note that finding no file matching the pattern is not an error, it simply return no file name.

◆ SearchWildcard()

template<class CONTAINER >
bool ts::SearchWildcard ( CONTAINER &  container,
const UString root,
const UString pattern,
size_t  max_levels = 64,
bool  skip_symlinks = true 
)
inline

Search all files matching a specified wildcard pattern in a directory tree.

Template Parameters
CONTAINERA container class of UString as defined by the C++ Standard Template Library (STL).
Parameters
[out]containerA container of UString receiving the the names of all files matching the wildcard.
[in]rootRoot directory into which the files are searched.
[in]patternA file path pattern with wildcards. The syntax of the wildcards is system-dependent.
[in]max_levelsMaximum number of directory recursions. Since some operating systems allow loops in the file system, it is a good idea to set some limit to avoid infinite recursion.
[in]skip_symlinksIf true, do not recurse through symbolic links to directories.
Returns
True on success, false on error. Note that finding no file matching the pattern is not an error, it simply return no file name.

◆ SearchExecutableFile()

UString ts::SearchExecutableFile ( const UString fileName,
const UString pathName = PATH_ENVIRONMENT_VARIABLE 
)

Search an executable file.

Parameters
[in]fileNameName of the file to search.
[in]pathNameName of the seach path environment variable.
Returns
The path to an existing file or an empty path if not found.

◆ SearchConfigurationFile()

UString ts::SearchConfigurationFile ( const UString fileName)

Search a configuration file.

Parameters
[in]fileNameName of the file to search. If fileName is not found and does not contain any directory part, search this file in the following places:
  • All directories in TSPLUGINS_PATH environment variable.
  • Directory of the current executable.
  • Directory ../etc/tsduck from current executable (UNIX only).
  • Directory ../../etc/tsduck from current executable (UNIX only).
  • Directory ../lib64/tsduck from current executable (64-bit UNIX only).
  • Directory ../lib/tsduck from current executable (UNIX only).
  • Directory ../share/tsduck from current executable (UNIX only).
  • All directories in LD_LIBRARY_PATH environment variable (UNIX only).
  • All directories in PATH (UNIX) or Path (Windows) environment variable.
Returns
The path to an existing file or an empty string if not found.

◆ UserConfigurationFileName()

UString ts::UserConfigurationFileName ( const UString fileName,
const UString winFileName = UString() 
)

Build the name of a user-specific configuration file.

Parameters
[in]fileNameBase name of the configuration file.
[in]winFileNameAlternative base name on Windows. If empty, fileName is used.
Returns
The path to the user-specific configuration file. The file may exist or not. The default file location depends on the operating system:
  • Windows: %APPDATA%\tsduck
  • Unix: $HOME

Variable Documentation

◆ DEFAULT_CSV_SEPARATOR

constexpr const UChar* ts::DEFAULT_CSV_SEPARATOR = u","
constexpr

Default separator in CSV (comma-separated values) format.

CSV files are suitable for analysis using tools such as Microsoft Excel.