Table of Contents

Class DirectoryInfo

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

Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.

public sealed class DirectoryInfo : FileSystemInfo
Inheritance
DirectoryInfo
Inherited Members
Extension Methods

Constructors

DirectoryInfo(string)

Initializes a new instance of the DirectoryInfo class on the specified path.

public DirectoryInfo(string path)

Parameters

path string

Properties

Exists

Gets a value indicating whether the file or directory exists.

public override bool Exists { get; }

Property Value

bool

Name

Gets the name of this DirectoryInfo instance.

public override string Name { get; }

Property Value

string

Parent

Gets the parent directory of a specified subdirectory.

public DirectoryInfo Parent { get; }

Property Value

DirectoryInfo

Root

Gets the root portion of the directory.

public DirectoryInfo Root { get; }

Property Value

DirectoryInfo

An object that represents the root of the directory.

Methods

Create()

Creates a directory.

public void Create()

CreateSubdirectory(string)

Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class.

public DirectoryInfo CreateSubdirectory(string path)

Parameters

path string

Returns

DirectoryInfo

Delete()

Deletes a file or directory.

public override void Delete()

Delete(bool)

Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.

public void Delete(bool recursive)

Parameters

recursive bool

true to delete this directory, its subdirectories, and all files; otherwise, false.

GetDirectories()

Returns the subdirectories of the current directory.

public DirectoryInfo[] GetDirectories()

Returns

DirectoryInfo[]

An array of DirectoryInfo objects.

GetFiles()

Returns a file list from the current directory.

public FileInfo[] GetFiles()

Returns

FileInfo[]

An array of type FileInfo.

Exceptions

IOException

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

HandleRefreshError()

Handler for the case when the file or directory does not exist.

protected override void HandleRefreshError()

MoveTo(string)

Moves a DirectoryInfo instance and its contents to a new path.

public void MoveTo(string destDirName)

Parameters

destDirName string

The name and path to which to move this directory. The destination cannot be another disk volume or a directory with the identical name. It can be an existing directory to which you want to add this directory as a subdirectory.

Exceptions

IOException

An attempt was made to move a directory to a different volume. -or- destDirName already exists. -or- The source directory does not exist. -or- The source or destination directory name is null.

ArgumentNullException

destDirName is null.

ToString()

Returns the original path that was passed to the DirectoryInfo constructor. Use the FullName or Name properties for the full path or file/directory name instead of this method.

public override string ToString()

Returns

string

The original path that was passed by the user.