Table of Contents

Class Directory

Namespace
System.IO
Assembly
System.IO.FileSystem.dll

Class for managing directories

public static class Directory
Inheritance
Directory
Inherited Members

Methods

CreateDirectory(string)

Creates directory with the provided path.

public static void CreateDirectory(string path)

Parameters

path string

Path and name of the directory to create.

Exceptions

IOException

Path for creating the folder doesn't exist. This method does not create directories recursively.

Delete(string, bool)

Deletes directory from storage.

public static void Delete(string path, bool recursive = false)

Parameters

path string

Path to the directory to be removed.

recursive bool

Parameter to be implemented.

Exceptions

IOException

This method will throw DirectoryNotEmpty exception if folder is not empty.

Exists(string)

Determines whether the specified directory exists.

public static bool Exists(string path)

Parameters

path string

Path to the directory.

Returns

bool

True if directory under given path exists, otherwise it returns false.

Exceptions

ArgumentNullException

Path must be defined.

IOException

Invalid drive or path to the parent folder doesn't exist.

GetDirectories(string)

List directories from the specified folder.

public static string[] GetDirectories(string path)

Parameters

path string

Returns

string[]

When this method completes successfully, it returns an array of absolute paths to the subfolders in the specified directory.

Exceptions

IOException

Logical drive or a directory under given path does not exist.

GetFiles(string)

List files from the specified folder.

public static string[] GetFiles(string path)

Parameters

path string

Path to the directory to list files from.

Returns

string[]

When this method completes successfully, it returns a array of paths of the files in the given folder.

Exceptions

IOException

Logical drive or a directory under given path does not exist.

GetLastWriteTime(string)

Determines the time of the last write/modification to directory under given path.

public static DateTime GetLastWriteTime(string path)

Parameters

path string

Returns

DateTime

Time of the last write/modification.

Exceptions

IOException

Logical drive or a directory under given path does not exist.

GetLogicalDrives()

Determines a list of available logical drives.

public static string[] GetLogicalDrives()

Returns

string[]

String[] of available drives, ex. "D:\"

Move(string, string)

Moves directory from specified path to a new location.

public static void Move(string sourcePath, string destinationPath)

Parameters

sourcePath string

Name of directory to move. Absolute path.

destinationPath string

New path and name for the directory.

Exceptions

Exception

Source directory not existing or destination folder already existing.