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