Directory Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

System..::..Object
  System.IO..::..Directory

Namespace:  System.IO
Assembly:  System.IO (in System.IO.dll)

public sealed class Directory

The Directory type exposes the following members.

  NameDescription
Public methodStatic memberCreateDirectoryCreates all directories and subdirectories in the specified path.
Public methodStatic memberDelete(String)Deletes an empty directory from a specified path.
Public methodStatic memberDelete(String, Boolean)Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
Public methodStatic memberEnumerateDirectoriesReturns an enumerable collection of directory names in a specified path.
Public methodStatic memberEnumerateFilesReturns an enumerable collection of file names in a specified path.
Public methodStatic memberEnumerateFileSystemEntriesReturns an enumerable collection of file-system entries in a specified path.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodStatic memberExistsDetermines whether the given path refers to an existing directory on disk.
Public methodStatic memberGetCurrentDirectoryGets the current working directory of the application.
Public methodStatic memberGetDirectoriesGets the names of subdirectories (including their paths) in the specified directory.
Public methodStatic memberGetFilesReturns the names of files (including their paths) in the specified directory.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberMoveMoves a file or a directory and its contents to a new location.
Public methodStatic memberSetCurrentDirectorySets the application's current working directory to the specified directory.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Use the Directory class for typical operations such as copying, moving, renaming, creating, and deleting directories. You can also use the Directory class to get and set DateTime information related to the creation, access, and writing of a directory.

Because all Directory methods are static, it might be more efficient to use a Directory method rather than a corresponding DirectoryInfo instance method if you want to perform only one action. Most Directory methods require the path to the directory that you are manipulating.

The static methods of the Directory class perform security checks on all methods. If you are going to reuse an object several times, consider using the corresponding instance method of DirectoryInfo instead, because the security check will not always be necessary.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show: