Directory

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 void CreateDirectory_(const String&)Creates all directories in the specified path if those don’t exist.
static void Delete(const String&, bool)Removes the specified file or directory. Does not throw.
static StringEnumerablePtr 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 StringEnumerablePtr 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 StringEnumerablePtr 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 bool Exists(const String&)Determines if the specified path refers to existing directory.
static DateTime GetCreationTime(const String&)Returns the creation time of the specified entity as local time.
static DateTime GetCreationTimeUtc(const String&)Returns the creation time of the specified entity as UTC time.
static String GetCurrentDirectory()Returns the full name (including path) of the current directory.
static ArrayPtr<String> 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 String GetDirectoryRoot(const String&)Returns the root directory of the specified path.
static ArrayPtr<String> 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 ArrayPtr<String> 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 DateTime GetLastAccessTime(const String&)Returns the last access time of the specified entity as local time.
static DateTime GetLastAccessTimeUtc(const String&)Returns the last access time of the specified entity as UTC time.
static DateTime GetLastWriteTime(const String&)Returns the last write time of the specified entity as local time.
static DateTime GetLastWriteTimeUtc(const String&)Returns the last write time of the specified entity as UTC time.
static ArrayPtr<String> GetLogicalDrives()NOT IMPLEMENTED.
static DirectoryInfoPtr GetParent(const String&)Returns a shared pointer to DirectoryInfo object representing the parent directory of the specified entity.
static void 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 void SetCreationTime(const String&, DateTime)Sets the creation time of the specified entity as local time.
static void SetCreationTimeUtc(const String&, DateTime)Sets the creation time of the specified entity as UTC time.
static void SetCurrentDirectory(const String&)Sets the current directory.
static void SetLastAccessTime(const String&, DateTime)Sets the last access time of the specified entity as local time.
static void SetLastAccessTimeUtc(const String&, DateTime)Sets the last access time of the specified entity as UTC time.
static void SetLastWriteTime(const String&, DateTime)Sets the last write time of the specified entity as local time.
static void 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