DirectoryInfo Class
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
Inheritance Hierarchy
System. . :: . .Object
System. . :: . .MarshalByRefObject
System.IO. . :: . .FileSystemInfo
System.IO..::..DirectoryInfo
Namespace: System.IO
Assembly: System.IO (in System.IO.dll)
Syntax
'Declaration
Public NotInheritable Class DirectoryInfo _
Inherits FileSystemInfo
public sealed class DirectoryInfo : FileSystemInfo
public ref class DirectoryInfo sealed : public FileSystemInfo
[<Sealed>]
type DirectoryInfo =
class
inherit FileSystemInfo
end
public final class DirectoryInfo extends FileSystemInfo
The DirectoryInfo type exposes the following members.
Constructors
Name | Description | |
---|---|---|
DirectoryInfo | Initializes a new instance of the DirectoryInfo class on the specified path. |
Top
Properties
Name | Description | |
---|---|---|
Attributes | Gets or sets the attributes for the current file or directory. (Inherited from FileSystemInfo.) | |
CreationTime | Gets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.) | |
CreationTimeUtc | Gets or sets the creation time, in coordinated universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.) | |
Exists | Gets a value indicating whether the directory exists. (Overrides FileSystemInfo. . :: . .Exists.) | |
Extension | Gets the string representing the extension part of the file. (Inherited from FileSystemInfo.) | |
FullName | Gets the full path of the directory or file. (Inherited from FileSystemInfo.) | |
LastAccessTime | Gets or sets the time the current file or directory was last accessed. (Inherited from FileSystemInfo.) | |
LastAccessTimeUtc | Gets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.) | |
LastWriteTime | Gets or sets the time when the current file or directory was last written to. (Inherited from FileSystemInfo.) | |
LastWriteTimeUtc | Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.) | |
Name | Gets the name of this DirectoryInfo instance. (Overrides FileSystemInfo. . :: . .Name.) | |
Parent | Gets the parent directory of a specified subdirectory. | |
Root | Gets the root portion of the directory. |
Top
Methods
Name | Description | |
---|---|---|
Create | Creates a directory. | |
CreateSubdirectory | Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class. | |
Delete() () () () | Deletes this DirectoryInfo if it is empty. (Overrides FileSystemInfo. . :: . .Delete() () () ().) | |
Delete(Boolean) | Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files. | |
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
GetDirectories | Returns the subdirectories of the current directory. | |
GetFiles | Returns a file list from the current 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.) | |
MoveTo | Moves a DirectoryInfo instance and its contents to a new path. | |
Refresh | Refreshes the state of the object. (Inherited from FileSystemInfo.) | |
ToString | Returns the original path that was passed by the user. (Overrides Object. . :: . .ToString() () () ().) |
Top
Remarks
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.
Note
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.
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.