Asposecpplib
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...

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 void CreateDirectory_ (const String &path)
 Creates all directories in the specified path if those don't exist. More...
 
static void Delete (const String &path, bool recursive=false)
 Removes the specified file or directory. Does not throw. More...
 
static 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 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 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 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 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 ArrayPtr< StringGetLogicalDrives ()
 NOT IMPLEMENTED. More...
 
static bool Exists (const String &path)
 Determines if the specified path refers to existing directory. More...
 
static DateTime GetCreationTime (const String &path)
 Returns the creation time of the specified entity as local time. More...
 
static DateTime GetCreationTimeUtc (const String &path)
 Returns the creation time of the specified entity as UTC time. More...
 
static DateTime GetLastAccessTime (const String &path)
 Returns the last access time of the specified entity as local time. More...
 
static DateTime GetLastAccessTimeUtc (const String &path)
 Returns the last access time of the specified entity as UTC time. More...
 
static DateTime GetLastWriteTime (const String &path)
 Returns the last write time of the specified entity as local time. More...
 
static DateTime GetLastWriteTimeUtc (const String &path)
 Returns the last write time of the specified entity as UTC time. More...
 
static void SetCreationTime (const String &path, DateTime date)
 Sets the creation time of the specified entity as local time. More...
 
static void SetCreationTimeUtc (const String &path, DateTime date)
 Sets the creation time of the specified entity as UTC time. More...
 
static void SetLastAccessTime (const String &path, DateTime date)
 Sets the last access time of the specified entity as local time. More...
 
static void SetLastAccessTimeUtc (const String &path, DateTime date)
 Sets the last access time of the specified entity as UTC time. More...
 
static void SetLastWriteTime (const String &path, DateTime date)
 Sets the last write time of the specified entity as local time. More...
 
static void SetLastWriteTimeUtc (const String &path, DateTime date)
 Sets the last write time of the specified entity as UTC time. More...
 
static String GetCurrentDirectory ()
 Returns the full name (including path) of the current directory. More...
 
static String GetDirectoryRoot (const String &path)
 Returns the root directory of the specified path. More...
 
static DirectoryInfoPtr GetParent (const String &path)
 Returns a shared pointer to DirectoryInfo object representing the parent directory of the specified entity. More...
 
static 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 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
*/
static bool Exists(const String &path)
Determines if the specified path refers to existing directory.
static DateTime GetLastWriteTime(const String &path)
Returns the last write time of the specified entity as local time.
static DateTime GetCreationTime(const String &path)
Returns the creation time of the specified entity as local time.
static DateTime GetLastAccessTime(const String &path)
Returns the last access time of the specified entity as local time.
static String GetTempPath()
Returns the path of the current user's temporary directory.
String class used across the library. Is a substitute for C# System.String when porting code....
Definition: string.h:125

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 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 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 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 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 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 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 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 String System::IO::Directory::GetCurrentDirectory ( )
static

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

◆ GetDirectories()

static 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 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 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 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 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 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 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 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 ArrayPtr<String> System::IO::Directory::GetLogicalDrives ( )
static

NOT IMPLEMENTED.

Exceptions
IOExceptionAlways

◆ GetParent()

static 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 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 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 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 void System::IO::Directory::SetCurrentDirectory ( const String path)
static

Sets the current directory.

Parameters
pathThe path to the directory to make current

◆ SetLastAccessTime()

static 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 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 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 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