System::IO::Directory class

Directory class

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

class Directory

Methods

MethodDescription
static CreateDirectory_(const String&)Creates all directories in the specified path if those don’t exist.
static Delete(const String&, bool)Removes the specified file or directory. Does not throw.
static EnumerateDirectories(const String&, const String&, SearchOption)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.
static EnumerateFiles(const String&, const String&, SearchOption)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.
static EnumerateFileSystemEntries(const String&, const String&, SearchOption)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.
static Exists(const String&)Determines if the specified path refers to existing directory.
static GetCreationTime(const String&)Returns the creation time of the specified entity as local time.
static GetCreationTimeUtc(const String&)Returns the creation time of the specified entity as UTC time.
static GetCurrentDirectory()Returns the full name (including path) of the current directory.
static GetDirectories(const String&, const String&, SearchOption)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.
static GetDirectoryRoot(const String&)Returns the root directory of the specified path.
static GetFiles(const String&, const String&, SearchOption)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.
static GetFileSystemEntries(const String&, const String&, SearchOption)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.
static GetLastAccessTime(const String&)Returns the last access time of the specified entity as local time.
static GetLastAccessTimeUtc(const String&)Returns the last access time of the specified entity as UTC time.
static GetLastWriteTime(const String&)Returns the last write time of the specified entity as local time.
static GetLastWriteTimeUtc(const String&)Returns the last write time of the specified entity as UTC time.
static GetLogicalDrives()NOT IMPLEMENTED.
static GetParent(const String&)Returns a shared pointer to DirectoryInfo object representing the parent directory of the specified entity.
static Move(const String&, const String&)Moves the specified entity to the new location. If the entity to move is a directory, it is moved with all its content.
static SetCreationTime(const String&, DateTime)Sets the creation time of the specified entity as local time.
static SetCreationTimeUtc(const String&, DateTime)Sets the creation time of the specified entity as UTC time.
static SetCurrentDirectory(const String&)Sets the current directory.
static SetLastAccessTime(const String&, DateTime)Sets the last access time of the specified entity as local time.
static SetLastAccessTimeUtc(const String&, DateTime)Sets the last access time of the specified entity as UTC time.
static SetLastWriteTime(const String&, DateTime)Sets the last write time of the specified entity as local time.
static SetLastWriteTimeUtc(const String&, DateTime)Sets the last write time of the specified entity as UTC time.

Typedefs

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

Remarks

#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
*/

See Also