System::IO::Directory Class Reference

Contains methods for manipulating directories. This is a static type with no instance services. You should never create instances of it by any means. More...

#include "directory.h"

Public Types

using StringEnumerablePtr = SharedPtr< Collections::Generic::IEnumerable< String > >
 An alias for a shared pointer to IEnumerable object that enumerates over a set of String objects. More...
 

Static Public Member Functions

static ASPOSECPP_SHARED_API void CreateDirectory_ (const String &path)
 Creates all directories in the specified path if those don't exist. More...
 
static ASPOSECPP_SHARED_API void Delete (const String &path, bool recursive=false)
 Removes the specified file or directory. Does not throw. More...
 
static ASPOSECPP_SHARED_API StringEnumerablePtr EnumerateDirectories (const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
 Searches for the directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory. More...
 
static ASPOSECPP_SHARED_API StringEnumerablePtr EnumerateFiles (const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
 Searches for the files that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory. More...
 
static StringEnumerablePtr EnumerateFileSystemEntries (const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
 Searches for the files and directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory. More...
 
static ASPOSECPP_SHARED_API ArrayPtr< StringGetDirectories (const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
 Searches for the directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory. More...
 
static ASPOSECPP_SHARED_API ArrayPtr< StringGetFiles (const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
 Searches for the files that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory. More...
 
static ASPOSECPP_SHARED_API ArrayPtr< StringGetFileSystemEntries (const String &path, const String &searchPattern=u"*", SearchOption searchOption=SearchOption::TopDirectoryOnly)
 Searches for the files and directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory. More...
 
static ASPOSECPP_SHARED_API ArrayPtr< StringGetLogicalDrives ()
 NOT IMPLEMENTED. More...
 
static ASPOSECPP_SHARED_API bool Exists (const String &path)
 Determines if the specified path refers to existing directory. More...
 
static ASPOSECPP_SHARED_API DateTime GetCreationTime (const String &path)
 Returns the creation time of the specified entity as local time. More...
 
static ASPOSECPP_SHARED_API DateTime GetCreationTimeUtc (const String &path)
 Returns the creation time of the specified entity as UTC time. More...
 
static ASPOSECPP_SHARED_API DateTime GetLastAccessTime (const String &path)
 Returns the last access time of the specified entity as local time. More...
 
static ASPOSECPP_SHARED_API DateTime GetLastAccessTimeUtc (const String &path)
 Returns the last access time of the specified entity as UTC time. More...
 
static ASPOSECPP_SHARED_API DateTime GetLastWriteTime (const String &path)
 Returns the last write time of the specified entity as local time. More...
 
static ASPOSECPP_SHARED_API DateTime GetLastWriteTimeUtc (const String &path)
 Returns the last write time of the specified entity as UTC time. More...
 
static ASPOSECPP_SHARED_API void SetCreationTime (const String &path, DateTime date)
 Sets the creation time of the specified entity as local time. More...
 
static ASPOSECPP_SHARED_API void SetCreationTimeUtc (const String &path, DateTime date)
 Sets the creation time of the specified entity as UTC time. More...
 
static ASPOSECPP_SHARED_API void SetLastAccessTime (const String &path, DateTime date)
 Sets the last access time of the specified entity as local time. More...
 
static ASPOSECPP_SHARED_API void SetLastAccessTimeUtc (const String &path, DateTime date)
 Sets the last access time of the specified entity as UTC time. More...
 
static ASPOSECPP_SHARED_API void SetLastWriteTime (const String &path, DateTime date)
 Sets the last write time of the specified entity as local time. More...
 
static ASPOSECPP_SHARED_API void SetLastWriteTimeUtc (const String &path, DateTime date)
 Sets the last write time of the specified entity as UTC time. More...
 
static ASPOSECPP_SHARED_API String GetCurrentDirectory ()
 Returns the full name (including path) of the current directory. More...
 
static ASPOSECPP_SHARED_API String GetDirectoryRoot (const String &path)
 Returns the root directory of the specified path. More...
 
static ASPOSECPP_SHARED_API DirectoryInfoPtr GetParent (const String &path)
 Returns a shared pointer to DirectoryInfo object representing the parent directory of the specified entity. More...
 
static ASPOSECPP_SHARED_API void Move (const String &sourceDirName, const String &destDirName)
 Moves the specified entity to the new location. If the entity to move is a directory, it is moved with all its content. More...
 
static ASPOSECPP_SHARED_API void SetCurrentDirectory (const String &path)
 Sets the current directory. More...
 

Detailed Description

Contains methods for manipulating directories. This is a static type with no instance services. You should never create instances of it by any means.

#include "system/io/directory.h"
#include "system/io/path.h"
#include "system/string.h"
#include <iostream>
void PrintMessage(const System::String &path)
{
std::cout << "Directory '" << path << (System::IO::Directory::Exists(path) ? "' exists." : "' doesn't exist.") << std::endl;
}
int main()
{
// Create strings that contain paths to directories.
System::String discPath(u"C:\\");
System::String directoryPath(u"C:\\Some directory");
auto tempPath = System::IO::Path::GetTempPath();
// Check if directories exist.
PrintMessage(discPath);
PrintMessage(directoryPath);
PrintMessage(tempPath);
// Print the temp directory information.
std::cout <<
"Creation Time: " << System::IO::Directory::GetCreationTime(tempPath) << std::endl <<
"Last Access Time: " << System::IO::Directory::GetLastAccessTime(tempPath) << std::endl <<
"Last Write Time: " << System::IO::Directory::GetLastWriteTime(tempPath) << std::endl;
return 0;
}
/*
This code example produces the following output:
Directory 'C:\' exists.
Directory 'C:\Some directory' doesn't exist.
Directory 'C:\Users\lanor\AppData\Local\Temp\' exists.
Creation Time: 27.08.2021 14:21:42
Last Access Time: 07.10.2021 12:16:41
Last Write Time: 07.10.2021 12:16:41
*/

Member Typedef Documentation

◆ StringEnumerablePtr

An alias for a shared pointer to IEnumerable object that enumerates over a set of String objects.

Member Function Documentation

◆ CreateDirectory_()

static ASPOSECPP_SHARED_API void System::IO::Directory::CreateDirectory_ ( const String path)
static

Creates all directories in the specified path if those don't exist.

Parameters
pathThe path containing the directories to create

◆ Delete()

static ASPOSECPP_SHARED_API void System::IO::Directory::Delete ( const String path,
bool  recursive = false 
)
static

Removes the specified file or directory. Does not throw.

Parameters
pathThe path to the directory or file to be removed
recursiveIf path specifies a non-empty directory then recursive specifies if if all directory's content should be removed recursively; if the directory specified by path is not empty and recursive is 'false' then the operation fails

◆ EnumerateDirectories()

static ASPOSECPP_SHARED_API StringEnumerablePtr System::IO::Directory::EnumerateDirectories ( const String path,
const String searchPattern = u"*",
SearchOption  searchOption = SearchOption::TopDirectoryOnly 
)
static

Searches for the directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory.

Parameters
pathFull or relative path to the directory to search in
searchPatternThe name pattern of the directories to search for
searchOptionSpecifies whether the search has to be performed in the specified directory only or in the whole directory tree rooted in the specified directory
Returns
The enumerable collection of full paths of the found directories whose names match searchPattern

◆ EnumerateFiles()

static ASPOSECPP_SHARED_API StringEnumerablePtr System::IO::Directory::EnumerateFiles ( const String path,
const String searchPattern = u"*",
SearchOption  searchOption = SearchOption::TopDirectoryOnly 
)
static

Searches for the files that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory.

Parameters
pathFull or relative path to the directory to search in
searchPatternThe name pattern of the files to search for
searchOptionSpecifies whether the search has to be performed in the specified directory only or in the whole directory tree rooted in the specified directory
Returns
The enumerable collection of full paths of the found files whose names match searchPattern

◆ EnumerateFileSystemEntries()

static StringEnumerablePtr System::IO::Directory::EnumerateFileSystemEntries ( const String path,
const String searchPattern = u"*",
SearchOption  searchOption = SearchOption::TopDirectoryOnly 
)
static

Searches for the files and directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory.

Parameters
pathFull or relative path to the directory to search in
searchPatternThe name pattern of the files and directories to search for
searchOptionSpecifies whether the search has to be performed in the specified directory only or in the whole directory tree rooted in the specified directory
Returns
The enumerable collection of full paths of the found files and directories whose names match searchPattern

◆ Exists()

static ASPOSECPP_SHARED_API bool System::IO::Directory::Exists ( const String path)
static

Determines if the specified path refers to existing directory.

Parameters
pathThe path to check
Returns
True if the specified path refers to existing directory, otherwise - false

◆ GetCreationTime()

static ASPOSECPP_SHARED_API DateTime System::IO::Directory::GetCreationTime ( const String path)
static

Returns the creation time of the specified entity as local time.

Parameters
pathThe entity whose creating time to retrieve
Returns
A DateTime object representing the creation time of the specified entity as local time

◆ GetCreationTimeUtc()

static ASPOSECPP_SHARED_API DateTime System::IO::Directory::GetCreationTimeUtc ( const String path)
static

Returns the creation time of the specified entity as UTC time.

Parameters
pathThe entity whose creating time to retrieve
Returns
A DateTime object representing the creation time of the specified entity as UTC time

◆ GetCurrentDirectory()

static ASPOSECPP_SHARED_API String System::IO::Directory::GetCurrentDirectory ( )
static

Returns the full name (including path) of the current directory.

◆ GetDirectories()

static ASPOSECPP_SHARED_API ArrayPtr<String> System::IO::Directory::GetDirectories ( const String path,
const String searchPattern = u"*",
SearchOption  searchOption = SearchOption::TopDirectoryOnly 
)
static

Searches for the directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory.

Parameters
pathFull or relative path to the directory to search in
searchPatternThe name pattern of the directories to search for
searchOptionSpecifies whether the search has to be performed in the specified directory only or in the whole directory tree rooted in the specified directory
Returns
An array of full paths of the found directories whose names match searchPattern

◆ GetDirectoryRoot()

static ASPOSECPP_SHARED_API String System::IO::Directory::GetDirectoryRoot ( const String path)
static

Returns the root directory of the specified path.

Parameters
pathA path from which a root directory is to be obtained
Returns
The name of the root directory in path

◆ GetFiles()

static ASPOSECPP_SHARED_API ArrayPtr<String> System::IO::Directory::GetFiles ( const String path,
const String searchPattern = u"*",
SearchOption  searchOption = SearchOption::TopDirectoryOnly 
)
static

Searches for the files that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory.

Parameters
pathFull or relative path to the directory to search in
searchPatternThe name pattern of the files to search for
searchOptionSpecifies whether the search has to be performed in the specified directory only or in the whole directory tree rooted in the specified directory
Returns
An array of full paths of the found files whose names match searchPattern

◆ GetFileSystemEntries()

static ASPOSECPP_SHARED_API ArrayPtr<String> System::IO::Directory::GetFileSystemEntries ( const String path,
const String searchPattern = u"*",
SearchOption  searchOption = SearchOption::TopDirectoryOnly 
)
static

Searches for the files and directories that satisfy the specified search criteria either in the specified directory or in the whole directory tree rooted in the specified directory.

Parameters
pathFull or relative path to the directory to search in
searchPatternThe name pattern of the files and directories to search for
searchOptionSpecifies whether the search has to be performed in the specified directory only or in the whole directory tree rooted in the specified directory
Returns
An array of full paths of the found files and directories whose names match searchPattern

◆ GetLastAccessTime()

static ASPOSECPP_SHARED_API DateTime System::IO::Directory::GetLastAccessTime ( const String path)
static

Returns the last access time of the specified entity as local time.

Parameters
pathThe entity whose last access time to retrieve
Returns
A DateTime object representing the last access time of the specified entity as local time

◆ GetLastAccessTimeUtc()

static ASPOSECPP_SHARED_API DateTime System::IO::Directory::GetLastAccessTimeUtc ( const String path)
static

Returns the last access time of the specified entity as UTC time.

Parameters
pathThe entity whose last access time to retrieve
Returns
A DateTime object representing the last access time of the specified entity as UTC time

◆ GetLastWriteTime()

static ASPOSECPP_SHARED_API DateTime System::IO::Directory::GetLastWriteTime ( const String path)
static

Returns the last write time of the specified entity as local time.

Parameters
pathThe entity whose last write time to retrieve
Returns
A DateTime object representing the last write time of the specified entity as local time

◆ GetLastWriteTimeUtc()

static ASPOSECPP_SHARED_API DateTime System::IO::Directory::GetLastWriteTimeUtc ( const String path)
static

Returns the last write time of the specified entity as UTC time.

Parameters
pathThe entity whose last write time to retrieve
Returns
A DateTime object representing the last write time of the specified entity as UTC time

◆ GetLogicalDrives()

static ASPOSECPP_SHARED_API ArrayPtr<String> System::IO::Directory::GetLogicalDrives ( )
static

NOT IMPLEMENTED.

Exceptions
IOExceptionAlways

◆ GetParent()

static ASPOSECPP_SHARED_API DirectoryInfoPtr System::IO::Directory::GetParent ( const String path)
static

Returns a shared pointer to DirectoryInfo object representing the parent directory of the specified entity.

Parameters
pathThe path to the entity whose parent is to be obtained
Returns
A shared pointer to DirectoryInfo object representing the parent directory of the entity specified by path

◆ Move()

static ASPOSECPP_SHARED_API void System::IO::Directory::Move ( const String sourceDirName,
const String destDirName 
)
static

Moves the specified entity to the new location. If the entity to move is a directory, it is moved with all its content.

Parameters
sourceDirNameA directory or file to move
destDirNameThe new location of sourceDirName

◆ SetCreationTime()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetCreationTime ( const String path,
DateTime  date 
)
static

Sets the creation time of the specified entity as local time.

Parameters
pathThe entity whose creating time to set
dateA DateTime object representing the time to set as local time

◆ SetCreationTimeUtc()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetCreationTimeUtc ( const String path,
DateTime  date 
)
static

Sets the creation time of the specified entity as UTC time.

Parameters
pathThe entity whose creating time to set
dateA DateTime object representing the time to set as UTC time

◆ SetCurrentDirectory()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetCurrentDirectory ( const String path)
static

Sets the current directory.

Parameters
pathThe path to the directory to make current

◆ SetLastAccessTime()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetLastAccessTime ( const String path,
DateTime  date 
)
static

Sets the last access time of the specified entity as local time.

Parameters
pathThe entity whose last access time to set
dateA DateTime object representing the time to set as local time

◆ SetLastAccessTimeUtc()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetLastAccessTimeUtc ( const String path,
DateTime  date 
)
static

Sets the last access time of the specified entity as UTC time.

Parameters
pathThe entity whose last access time to set
dateA DateTime object representing the time to set as UTC time

◆ SetLastWriteTime()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetLastWriteTime ( const String path,
DateTime  date 
)
static

Sets the last write time of the specified entity as local time.

Parameters
pathThe entity whose last write time to set
dateA DateTime object representing the time to set as local time

◆ SetLastWriteTimeUtc()

static ASPOSECPP_SHARED_API void System::IO::Directory::SetLastWriteTimeUtc ( const String path,
DateTime  date 
)
static

Sets the last write time of the specified entity as UTC time.

Parameters
pathThe entity whose last write time to set
dateA DateTime object representing the time to set as UTC time