Share via


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.

Inheritance Hierarchy

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

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

Syntax

'Declaration
Public NotInheritable Class Directory
public sealed class Directory
public ref class Directory sealed
[<Sealed>]
type Directory =  class end
public final class Directory

The Directory type exposes the following members.

Methods

  Name Description
Public methodStatic member CreateDirectory Creates all directories and subdirectories in the specified path.
Public methodStatic member Delete(String) Deletes an empty directory from a specified path.
Public methodStatic member Delete(String, Boolean) Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
Public methodStatic member EnumerateDirectories Returns an enumerable collection of directory names in a specified path.
Public methodStatic member EnumerateFiles Returns an enumerable collection of file names in a specified path.
Public methodStatic member EnumerateFileSystemEntries Returns an enumerable collection of file-system entries in a specified path.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodStatic member Exists Determines whether the given path refers to an existing directory on disk.
Public methodStatic member GetCurrentDirectory Gets the current working directory of the application.
Public methodStatic member GetDirectories Gets the names of subdirectories (including their paths) in the specified directory.
Public methodStatic member GetFiles Returns the names of files (including their paths) in the specified directory.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodStatic member Move Moves a file or a directory and its contents to a new location.
Public methodStatic member SetCurrentDirectory Sets the application's current working directory to the specified directory.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Thread Safety

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

See Also

Reference

System.IO Namespace