Export (0) Print
Expand All

DirectoryInfo Class

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

To browse the .NET Framework source code for this type, see the Reference Source.

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

[<Sealed>]
[<SerializableAttribute>]
[<ComVisibleAttribute(true)>]
type DirectoryInfo =  
    class 
        inherit FileSystemInfo 
    end

The DirectoryInfo type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkDirectoryInfoInitializes a new instance of the DirectoryInfo class on the specified path.
Top

  NameDescription
Public propertySupported by the XNA FrameworkAttributesGets or sets the attributes for the current file or directory. (Inherited from FileSystemInfo.)
Public propertySupported by the XNA FrameworkCreationTimeGets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.)
Public propertyCreationTimeUtcGets or sets the creation time, in coordinated universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.)
Public propertySupported by the XNA FrameworkExistsGets a value indicating whether the directory exists. (Overrides FileSystemInfo.Exists.)
Public propertySupported by the XNA FrameworkExtensionGets the string representing the extension part of the file. (Inherited from FileSystemInfo.)
Public propertySupported by the XNA FrameworkFullNameGets the full path of the directory or file. (Inherited from FileSystemInfo.)
Public propertySupported by the XNA FrameworkLastAccessTimeGets or sets the time the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public propertyLastAccessTimeUtcGets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public propertySupported by the XNA FrameworkLastWriteTimeGets or sets the time when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public propertyLastWriteTimeUtcGets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public propertySupported by the XNA FrameworkNameGets the name of this DirectoryInfo instance. (Overrides FileSystemInfo.Name.)
Public propertySupported by the XNA FrameworkParentGets the parent directory of a specified subdirectory.
Public propertySupported by the XNA FrameworkRootGets the root portion of the directory.
Top

  NameDescription
Public methodSupported by the XNA FrameworkCreate()Creates a directory.
Public methodCreate(DirectorySecurity)Creates a directory using a DirectorySecurity object.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodSupported by the XNA FrameworkCreateSubdirectory(String)Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class.
Public methodCreateSubdirectory(String, DirectorySecurity)Creates a subdirectory or subdirectories on the specified path with the specified security. The specified path can be relative to this instance of the DirectoryInfo class.
Public methodSupported by the XNA FrameworkDelete()Deletes this DirectoryInfo if it is empty. (Overrides FileSystemInfo.Delete().)
Public methodSupported by the XNA FrameworkDelete(Boolean)Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.
Public methodEnumerateDirectories()Returns an enumerable collection of directory information in the current directory.
Public methodEnumerateDirectories(String)Returns an enumerable collection of directory information that matches a specified search pattern.
Public methodEnumerateDirectories(String, SearchOption)Returns an enumerable collection of directory information that matches a specified search pattern and search subdirectory option.
Public methodEnumerateFiles()Returns an enumerable collection of file information in the current directory.
Public methodEnumerateFiles(String)Returns an enumerable collection of file information that matches a search pattern.
Public methodEnumerateFiles(String, SearchOption)Returns an enumerable collection of file information that matches a specified search pattern and search subdirectory option.
Public methodEnumerateFileSystemInfos()Returns an enumerable collection of file system information in the current directory.
Public methodEnumerateFileSystemInfos(String)Returns an enumerable collection of file system information that matches a specified search pattern.
Public methodEnumerateFileSystemInfos(String, SearchOption)Returns an enumerable collection of file system information that matches a specified search pattern and search subdirectory option.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetAccessControl()Gets a DirectorySecurity object that encapsulates the access control list (ACL) entries for the directory described by the current DirectoryInfo object.
Public methodGetAccessControl(AccessControlSections)Gets a DirectorySecurity object that encapsulates the specified type of access control list (ACL) entries for the directory described by the current DirectoryInfo object.
Public methodSupported by the XNA FrameworkGetDirectories()Returns the subdirectories of the current directory.
Public methodSupported by the XNA FrameworkGetDirectories(String)Returns an array of directories in the current DirectoryInfo matching the given search criteria.
Public methodGetDirectories(String, SearchOption)Returns an array of directories in the current DirectoryInfo matching the given search criteria and using a value to determine whether to search subdirectories.
Public methodSupported by the XNA FrameworkGetFiles()Returns a file list from the current directory.
Public methodSupported by the XNA FrameworkGetFiles(String)Returns a file list from the current directory matching the given search pattern.
Public methodGetFiles(String, SearchOption)Returns a file list from the current directory matching the given search pattern and using a value to determine whether to search subdirectories.
Public methodSupported by the XNA FrameworkGetFileSystemInfos()Returns an array of strongly typed FileSystemInfo entries representing all the files and subdirectories in a directory.
Public methodSupported by the XNA FrameworkGetFileSystemInfos(String)Retrieves an array of strongly typed FileSystemInfo objects representing the files and subdirectories that match the specified search criteria.
Public methodGetFileSystemInfos(String, SearchOption)Retrieves an array of FileSystemInfo objects that represent the files and subdirectories matching the specified search criteria.
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetObjectDataSets the SerializationInfo object with the file name and additional exception information. (Inherited from FileSystemInfo.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodSupported by the XNA FrameworkMoveToMoves a DirectoryInfo instance and its contents to a new path.
Public methodSupported by the XNA FrameworkRefreshRefreshes the state of the object. (Inherited from FileSystemInfo.)
Public methodSetAccessControlApplies access control list (ACL) entries described by a DirectorySecurity object to the directory described by the current DirectoryInfo object.
Public methodSupported by the XNA FrameworkToStringReturns the original path that was passed by the user. (Overrides Object.ToString().)
Top

NoteNote

To view the .NET Framework source code for this type, see the Reference Source. You can browse through the source code online, download the reference for offline viewing, and step through the sources (including patches and updates) during debugging; see instructions.

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

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

NoteNote

In members that accept a path as an input string, that path must be well-formed or an exception is raised. For example, if a path is fully qualified but begins with a space, the path is not trimmed in methods of the class. Therefore, the path is malformed and an exception is raised. Similarly, a path or a combination of paths cannot be fully qualified twice. For example, "c:\temp c:\windows" also raises an exception in most cases. Ensure that your paths are well-formed when using methods that accept a path string.

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

  • "c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.

  • "c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.

  • "MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.

  • "\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.

By default, full read/write access to new directories is granted to all users.

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

The following example demonstrates some of the main members of the DirectoryInfo class.

No code example is currently available or this language may not be supported.

The following example demonstrates how to copy a directory and its contents.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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:
© 2014 Microsoft