Directory Class

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

Summary

Provides static methods for the creation, moving, and enumeration of directories and subdirectories. This class cannot be inherited.

Syntax

[SerializableAttribute]
public static class Directory

Remarks

The Directory class provides methods that allow you to create, move, and enumerate directories and subdirectories. All methods on the Directory class are static, meaning you can call them directly on the class without creating an instance of it.

For more object-oriented operations on directories, use the DirectoryInfo class. The DirectoryInfo class provides instance methods that operate on a specific directory.

Members

  • CreateDirectory
    Creates all the necessary directories and subdirectories in the specified path unless they already exist.
    public static string CreateDirectory(string path) public static System.IO.DirectoryInfo CreateDirectory(string path) public static string CreateDirectory(string parentDir, string newDirName) public static System.IO.DirectoryInfo CreateDirectory(string parentDir, string newDirName)
  • Delete
    Deletes an empty directory from a specified path.
    public static void Delete(string path) public static void Delete(string path, bool recursive)
  • Exists
    Determines whether the given path refers to an existing directory on disk.
    public static bool Exists(string path)
  • GetDirectories
    Returns the names of subdirectories (including their paths) in the specified directory.
    public static string[] GetDirectories(string path) public static string[] GetDirectories(string path, string searchPattern) public static string[] GetDirectories(string path, string searchPattern, System.IO.SearchOption searchOption)
  • GetFiles
    Returns the names of all files (including their paths) in the specified directory.
    public static string[] GetFiles(string path) public static string[] GetFiles(string path, string searchPattern) public static string[] GetFiles(string path, string searchPattern, System.IO.SearchOption searchOption)
  • GetFileSystemEntries
    Returns the names of all files and subdirectories (including their paths) in the specified directory.
    public static string[] GetFileSystemEntries(string path) public static string[] GetFileSystemEntries(string path, string searchPattern) public static string[] GetFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption)
  • GetCurrentDirectory
    Gets the current working directory of the application.
    public static string GetCurrentDirectory()
  • Move
    Moves a specified directory and its contents to a new location.
    public static void Move(string sourceDirName, string destDirName)

See Also

  • DirectoryInfo
    Provides instance methods for creating, moving, and enumerating directories and subdirectories.
  • System.IO Namespace
    Contains types that allow reading and writing to and from various streams and files.