xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::path Class Reference
Inheritance diagram for xtd::io::path:
xtd::static_object

Definition

Performs operations on std::basic_string instances that contain file or directory path information. These operations are performed in a cross-platform manner.

Performs operations on std::basic_string instances that contain file or directory path information....
Definition path.hpp:37
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::static_objectxtd::io::path
Header
#include <xtd/io/path>
Namespace
xtd::io
Library
xtd.core

Public Fields

template<class char_t>
static auto alt_directory_separator_char () noexcept -> char_t
 Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.
 
static auto alt_directory_separator_char () noexcept -> char
 Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.
 
template<class char_t>
static auto directory_separator_char () noexcept -> char_t
 Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.
 
static auto directory_separator_char () noexcept -> char
 Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.
 
template<class char_t>
static auto path_separator () noexcept -> char_t
 A platform-specific separator character used to separate path strings in environment variables.
 
static auto path_separator () noexcept -> char
 A platform-specific separator character used to separate path strings in environment variables.
 
template<class char_t>
static auto volume_separator_char () noexcept -> char_t
 Provides a platform-specific volume separator character.
 
static auto volume_separator_char () noexcept -> char
 Provides a platform-specific volume separator character.
 

Public Static Methods

static auto change_extension (const xtd::string &path, const xtd::string &extension) -> xtd::string
 Changes the extension of a path string.
 
static auto combine (const xtd::string &path1, const xtd::string &path2) -> xtd::string
 Combines two path strings.
 
template<class type1_t, class type2_t, class type3_t>
static auto combine (type1_t path1, type2_t path2, type3_t path3) noexcept
 Combines three path strings.
 
template<class type1_t, class type2_t, class type3_t, class type4_t>
static auto combine (type1_t path1, type2_t path2, type3_t path3, type4_t path4) noexcept
 Combines four path strings.
 
template<class path_t>
static auto combine (path_t paths) noexcept -> xtd::string
 Combines path strings array.
 
static auto combine (const std::initializer_list< xtd::string > &paths) noexcept -> xtd::string
 Combines path strings array.
 
static auto get_directory_name (const xtd::string &path) -> xtd::string
 Returns the directory information for the specified path string.
 
static auto get_extension (const xtd::string &path) -> xtd::string
 Returns the extension of the specified path string.
 
static auto get_file_name (const xtd::string &path) -> xtd::string
 Returns the file name and extension of the specified path string.
 
static auto get_file_name_without_extension (const xtd::string &path) -> xtd::string
 Returns the file name of the specified path string without the extension.
 
static auto get_full_path (const xtd::string &path) -> xtd::string
 Returns the absolute path for the specified path string.
 
template<class char_t>
static auto get_invalid_path_chars () noexcept -> xtd::array< char_t >
 Gets an array containing the characters that are not allowed in path names.
 
static auto get_invalid_path_chars () noexcept -> xtd::array< char >
 Gets an array containing the characters that are not allowed in path names.
 
static auto get_path_root (const xtd::string &path) -> xtd::string
 Gets the root directory information of the specified path.
 
static auto get_random_file_name () -> xtd::string
 Returns a random folder name or file name.
 
static auto get_random_file_name (size_t name_length) -> xtd::string
 Returns a random folder name or file name with specified name length.
 
static auto get_random_file_name (size_t name_size, size_t extension_size) -> xtd::string
 Returns a random folder name or file name with specified name length, and extension length.
 
static auto get_temp_file_name () -> xtd::string
 Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.
 
static auto get_temp_path () noexcept -> xtd::string
 Returns the path of the current user's temporary folder.
 
static auto has_extension (const xtd::string &path) -> bool
 Determines whether a path includes a file name extension.
 
static auto is_path_rooted (const xtd::string &path) -> bool
 Gets a value indicating whether the specified path string contains absolute or relative path information.
 

Member Function Documentation

◆ alt_directory_separator_char() [1/2]

template<class char_t>
static auto xtd::io::path::alt_directory_separator_char ( ) -> char_t
inlinestaticnodiscardnoexcept

Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.

Returns
char_t character used to separate directory levels.
Remarks
This method can have the same value as directory_separator_char. alt_directory_separator_char and directory_separator_char are both valid for separating directory levels in a path string.
The value of this field is a slash ('/') on both Windows and Unix-based operating systems.
Examples
The following code example demonstrates the use of the alt_directory_separator_char() property.

◆ alt_directory_separator_char() [2/2]

static auto xtd::io::path::alt_directory_separator_char ( ) -> char
staticnodiscardnoexcept

Provides a platform-specific alternate character used to separate directory levels in a path string that reflects a hierarchical file system organization.

Returns
char character used to separate directory levels.
Remarks
This method can have the same value as directory_separator_char. alt_directory_separator_char and directory_separator_char are both valid for separating directory levels in a path string.
The value of this field is a slash ('/') on both Windows and Unix-based operating systems.
Examples
The following code example demonstrates the use of the alt_directory_separator_char() property.

◆ directory_separator_char() [1/2]

template<class char_t>
static auto xtd::io::path::directory_separator_char ( ) -> char_t
inlinestaticnodiscardnoexcept

Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.

Returns
char_t Platform-specific character used to separate directory levels.
Remarks
alt_directory_separator_char and directory_separator_char are both valid for separating directory levels in a path string.
Examples
The following code example demonstrates the use of the directory_separator_char() property.

◆ directory_separator_char() [2/2]

static auto xtd::io::path::directory_separator_char ( ) -> char
staticnodiscardnoexcept

Provides a platform-specific character used to separate directory levels in a path string that reflects a hierarchical file system organization.

Returns
char Platform-specific character used to separate directory levels.
Remarks
alt_directory_separator_char and directory_separator_char are both valid for separating directory levels in a path string.
Examples
The following code example demonstrates the use of the directory_separator_char() property.

◆ path_separator() [1/2]

template<class char_t>
static auto xtd::io::path::path_separator ( ) -> char_t
inlinestaticnodiscardnoexcept

A platform-specific separator character used to separate path strings in environment variables.

Examples
The following code example demonstrates the use of the PathSeparator() property.

◆ path_separator() [2/2]

static auto xtd::io::path::path_separator ( ) -> char
staticnodiscardnoexcept

A platform-specific separator character used to separate path strings in environment variables.

Examples
The following code example demonstrates the use of the PathSeparator() property.

◆ volume_separator_char() [1/2]

template<class char_t>
static auto xtd::io::path::volume_separator_char ( ) -> char_t
inlinestaticnodiscardnoexcept

Provides a platform-specific volume separator character.

Examples
The following code example demonstrates the use of the volume_separator_char() property.

◆ volume_separator_char() [2/2]

static auto xtd::io::path::volume_separator_char ( ) -> char
staticnodiscardnoexcept

Provides a platform-specific volume separator character.

Examples
The following code example demonstrates the use of the volume_separator_char() property.

◆ change_extension()

static auto xtd::io::path::change_extension ( const xtd::string & path,
const xtd::string & extension ) -> xtd::string
staticnodiscard

Changes the extension of a path string.

Parameters
pathThe path information to modify. The path cannot contain any of the characters defined in GetInvalidPathchar_ts.
extensionThe new extension (with or without a leading period). Specify null to remove an existing extension from path.
Returns
string The modified path information.
Note
On Windows-based desktop platforms, if path is an empty string (""), the path information is returned unmodified. If extension is empty string (""), the returned string contains the specified path with its extension removed. If path has no extension, and extension is not empty, the returned path string contains extension appended to the end of path.
Remarks
If neither path nor extension contains a period (.), change_extension adds the period.
The extension parameter can contain multiple periods and any valid path characters, and can be any length. If extension is empty (""), the returned string contains the contents of path with the last period and all characters following it removed.
If extension is an empty string, the returned path string contains the contents of path with any characters following the last period removed.
If extension does not contain a leading period, the period is added.
If path contains a multiple extension separated by multiple periods, the returned string contains the contents of path with the last period and all characters following it replaced by extension. For example, if path is "\Dir1\examples\pathtests.csx.txt" and extension is "cs", the modified path is "\Dir1\examples\pathtests.csx.cs".
It is not possible to verify that the returned results are valid in all scenarios. For example, if path is empty, extension is appended.

◆ combine() [1/5]

static auto xtd::io::path::combine ( const xtd::string & path1,
const xtd::string & path2 ) -> xtd::string
staticnodiscard

Combines two path strings.

Parameters
path1The first path.
path2The second path.
Returns
A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.
Remarks
an empty string if path contains one or more of the invalid characters.

◆ combine() [2/5]

template<class type1_t, class type2_t, class type3_t>
static auto xtd::io::path::combine ( type1_t path1,
type2_t path2,
type3_t path3 )
inlinestaticnodiscardnoexcept

Combines three path strings.

Parameters
path1The first path.
path2The second path.
path3The third path.
Returns
A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.
Remarks
an empty string if path contains one or more of the invalid characters.

◆ combine() [3/5]

template<class type1_t, class type2_t, class type3_t, class type4_t>
static auto xtd::io::path::combine ( type1_t path1,
type2_t path2,
type3_t path3,
type4_t path4 )
inlinestaticnodiscardnoexcept

Combines four path strings.

Parameters
path1The first path.
path2The second path.
path3The third path.
path4The fourth path.
Returns
A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.
Remarks
an empty string if path contains one or more of the invalid characters.

◆ combine() [4/5]

template<class path_t>
static auto xtd::io::path::combine ( path_t paths) -> xtd::string
inlinestaticnodiscardnoexcept

Combines path strings array.

Parameters
pathsThe path array.
Returns
A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.
Remarks
an empty string if path contains one or more of the invalid characters.

◆ combine() [5/5]

static auto xtd::io::path::combine ( const std::initializer_list< xtd::string > & paths) -> xtd::string
staticnodiscardnoexcept

Combines path strings array.

Parameters
pathsThe path array.
Returns
A string containing the combined paths. If one of the specified paths is a zero-length string, this method returns the other path. If path2 contains an absolute path, this method returns path2.
Remarks
an empty string if path contains one or more of the invalid characters.

◆ get_directory_name()

static auto xtd::io::path::get_directory_name ( const xtd::string & path) -> xtd::string
staticnodiscard

Returns the directory information for the specified path string.

Parameters
paththe path of a file or directory.
Returns
A string containing directory information for path, or null if path denotes a root directory, is the empty string ("").
Remarks
Returns string empty if path does not contain directory information.

◆ get_extension()

static auto xtd::io::path::get_extension ( const xtd::string & path) -> xtd::string
staticnodiscard

Returns the extension of the specified path string.

Parameters
pathThe path string from which to get the extension.
Returns
An xtd::string containing the extension of the specified path (including the ".") or xtd::string::empty.
Remarks
If path is empty, GetExtension returns string empty. If path does not have extension information, GetExtension returns string empty ("").

◆ get_file_name()

static auto xtd::io::path::get_file_name ( const xtd::string & path) -> xtd::string
staticnodiscard

Returns the file name and extension of the specified path string.

Parameters
pathThe path string from which to obtain the file name and extension.
Returns
The characters after the last directory separator character in path. If the last character of path is a directory or volume separator character, this method returns string empty ("").
Remarks
The separator characters used to determine the start of the file name are directory_separator_char and alt_directory_separator_char.

◆ get_file_name_without_extension()

static auto xtd::io::path::get_file_name_without_extension ( const xtd::string & path) -> xtd::string
staticnodiscard

Returns the file name of the specified path string without the extension.

Parameters
pathThe path of the file.
Returns
The string returned by xtd::io::path::get_file_name, minus the last period (.) and all characters following it.
Remarks
This method does not verify that the path or file name exists.

◆ get_full_path()

static auto xtd::io::path::get_full_path ( const xtd::string & path) -> xtd::string
staticnodiscard

Returns the absolute path for the specified path string.

Parameters
pathThe file or directory for which to obtain absolute path information.
Returns
A string containing the fully qualified location of path, such as "C:\\MyFile.txt".

◆ get_invalid_path_chars() [1/2]

template<class char_t>
static auto xtd::io::path::get_invalid_path_chars ( ) -> xtd::array<char_t>
inlinestaticnodiscardnoexcept

Gets an array containing the characters that are not allowed in path names.

Returns
An array containing the characters that are not allowed in path names.
Remarks
The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. The full set of invalid characters can vary by file system. For example, on Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as quote ("), less than (<), greater than (>), pipe (|), backspace (), null (\0) and tab (\t).

◆ get_invalid_path_chars() [2/2]

static auto xtd::io::path::get_invalid_path_chars ( ) -> xtd::array< char >
staticnodiscardnoexcept

Gets an array containing the characters that are not allowed in path names.

Returns
An array containing the characters that are not allowed in path names.
Remarks
The array returned from this method is not guaranteed to contain the complete set of characters that are invalid in file and directory names. The full set of invalid characters can vary by file system. For example, on Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as quote ("), less than (<), greater than (>), pipe (|), backspace (), null (\0) and tab (\t).

◆ get_path_root()

static auto xtd::io::path::get_path_root ( const xtd::string & path) -> xtd::string
staticnodiscard

Gets the root directory information of the specified path.

Parameters
pathThe path from which to obtain root directory information.
Returns
A string containing the root directory of path, such as "C:\", or null if
path is null, or an empty string if path does not contain root directory
information.

◆ get_random_file_name() [1/3]

static auto xtd::io::path::get_random_file_name ( ) -> xtd::string
staticnodiscard

Returns a random folder name or file name.

Returns
A random folder name or file name.
Remarks
The get_random_file_name method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, get_random_file_name does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.
The default name length is 8 and the default extension length is 3.

◆ get_random_file_name() [2/3]

static auto xtd::io::path::get_random_file_name ( size_t name_length) -> xtd::string
staticnodiscard

Returns a random folder name or file name with specified name length.

name_length The lname legnth.

Returns
A random folder name or file name.
Remarks
The get_random_file_name method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, get_random_file_name does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.
The default extension length is 0.

◆ get_random_file_name() [3/3]

static auto xtd::io::path::get_random_file_name ( size_t name_size,
size_t extension_size ) -> xtd::string
staticnodiscard

Returns a random folder name or file name with specified name length, and extension length.

name_length The name legnth.

extension_size The extension legnth.

Returns
A random folder name or file name.
Remarks
The get_random_file_name method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, get_random_file_name does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.

◆ get_temp_file_name()

static auto xtd::io::path::get_temp_file_name ( ) -> xtd::string
staticnodiscard

Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file.

Returns
The full path of the temporary file.
Remarks
This method creates a temporary file with a .TMP file extension. The temporary file is created within the user’s temporary folder, which is the path returned by the GetTempPath method.
The GetTempFileName method will raise an xtd::io_exception if it is used to create more than 65535 files without deleting previous temporary files.
The GetTempFileName method will raise an xtd::io_exception if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.

◆ get_temp_path()

static auto xtd::io::path::get_temp_path ( ) -> xtd::string
staticnodiscardnoexcept

Returns the path of the current user's temporary folder.

Returns
string The path to the temporary folder, ending with a backslash.
Remarks
This method checks for the existence of environment variables in the following order and uses the first path found:
  • The path specified by the TMP environment variable.
  • The path specified by the TEMP environment variable.
  • The path specified by the USERPROFILE environment variable.
  • The Windows directory.

◆ has_extension()

static auto xtd::io::path::has_extension ( const xtd::string & path) -> bool
staticnodiscard

Determines whether a path includes a file name extension.

Parameters
pathThe path to search for an extension.
Returns
true if the characters that follow the last directory separator (\ or /)
or volume separator (:) in the path include a period (.) followed by one
or more characters; otherwise, false.

◆ is_path_rooted()

static auto xtd::io::path::is_path_rooted ( const xtd::string & path) -> bool
staticnodiscard

Gets a value indicating whether the specified path string contains absolute or relative path information.

Parameters
pathThe path to test.
Returns
true if path contains an absolute path; otherwise, false.
Remarks
This method also returns false if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

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