System.IO.Directory Class

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

See Also: Directory Members

Syntax

[System.Runtime.InteropServices.ComVisible(true)]
public static class Directory

Remarks

Use the System.IO.Directory class for typical operations such as copying, moving, renaming, creating, and deleting directories.

The static methods of the System.IO.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 System.IO.DirectoryInfo instead, because the security check will not always be necessary.

If you are performing only one directory-related action, it might be more efficient to use a static System.IO.Directory method rather than a corresponding System.IO.DirectoryInfo instance method. Most System.IO.Directory methods require the path to the directory that you are manipulating.

Note:

In members that accept a string path parameter, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space (" c:\temp"), the path string isn't trimmed, so the path is considered malformed and an exception is raised. In addition, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception. Ensure that your paths are well-formed when using methods that accept a path string. For more information see System.IO.Path.

In members that accept a path, the path can refer to a file or a directory. You can use a full path, a relative path, or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:

By default, full read/write access to new directories is granted to all users. However, the app must have the correct security to access existing directories.

To demand permissions for a directory and all its subdirectories, end the path string with the directory separator character. (For example, "C:\Temp\" grants access to C:\Temp\ and all its subdirectories.) To demand permissions only for a specific directory, end the path string with a period. (For example, "C:\Temp\." grants access only to C:\Temp\, not to its subdirectories.)

In members that accept a searchPattern parameter, the search string can be any combination of literal characters and two wildcard characters; * and ?. This parameter does not recognize regular expressions. For more information, see the Directory.EnumerateDirectories(string, string) method or any other method that uses the searchPattern parameter.

For a list of common I/O tasks, see Common I/O Tasks.

System.IO.Directory and System.IO.DirectoryInfo are not supported for use in win8_appstore_long apps. For information about how to access files and folders in win8_appstore_long apps, see tp://msdn.microsoft.com/library/windows/apps/hh758319.aspx.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0