Share via


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
Public method DirectoryInfo Initializes a new instance of the DirectoryInfo class on the specified path.

Top

Properties

  Name Description
Public property Attributes Gets or sets the attributes for the current file or directory. (Inherited from FileSystemInfo.)
Public property CreationTime Gets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.)
Public property CreationTimeUtc Gets or sets the creation time, in coordinated universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.)
Public property Exists Gets a value indicating whether the directory exists. (Overrides FileSystemInfo. . :: . .Exists.)
Public property Extension Gets the string representing the extension part of the file. (Inherited from FileSystemInfo.)
Public property FullName Gets the full path of the directory or file. (Inherited from FileSystemInfo.)
Public property LastAccessTime Gets or sets the time the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public property LastAccessTimeUtc Gets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public property LastWriteTime Gets or sets the time when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public property LastWriteTimeUtc Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public property Name Gets the name of this DirectoryInfo instance. (Overrides FileSystemInfo. . :: . .Name.)
Public property Parent Gets the parent directory of a specified subdirectory.
Public property Root Gets the root portion of the directory.

Top

Methods

  Name Description
Public method Create Creates a directory.
Public method CreateSubdirectory Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the DirectoryInfo class.
Public method Delete() () () () Deletes this DirectoryInfo if it is empty. (Overrides FileSystemInfo. . :: . .Delete() () () ().)
Public method Delete(Boolean) Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method GetDirectories Returns the subdirectories of the current directory.
Public method GetFiles Returns a file list from the current directory.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method MoveTo Moves a DirectoryInfo instance and its contents to a new path.
Public method Refresh Refreshes the state of the object. (Inherited from FileSystemInfo.)
Public method 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.

See Also

Reference

System.IO Namespace