Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​IO.​DirectoryInfo
Assembly: System.Runtime
Inheritance: object → MarshalByRefObject → FileSystemInfo → DirectoryInfo
Implemented Interfaces
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
Fields and Constants
protected
string
FullPath
Represents the fully qualified path of the directory or file.
protected
string
OriginalPath
The path originally specified by the user, whether relative or absolute.
Properties
public
bool
Exists
Gets a value indicating whether the directory exists.
public
string
Name
Gets the name of this <see cref="T:System.IO.DirectoryInfo" /> instance.
public
DirectoryInfo
Parent
Gets the parent directory of a specified subdirectory.
public
DirectoryInfo
Root
Gets the root portion of the directory.
public
FileAttributes
Attributes
Gets or sets the attributes for the current file or directory.
public
DateTime
CreationTime
Gets or sets the creation time of the current file or directory.
public
DateTime
CreationTimeUtc
Gets or sets the creation time, in coordinated universal time (UTC), of the current file or directory.
public
string
Extension
Gets the extension part of the file name, including the leading dot <c>.</c> even if it is the entire file name, or an empty string if no extension is present.
public
string
FullName
Gets the full path of the directory or file.
public
DateTime
LastAccessTime
Gets or sets the time the current file or directory was last accessed.
public
DateTime
LastAccessTimeUtc
Gets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed.
public
DateTime
LastWriteTime
Gets or sets the time when the current file or directory was last written to.
public
DateTime
LastWriteTimeUtc
Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to.
public
string
LinkTarget
Gets the target path of the link located in <see cref="P:System.IO.FileSystemInfo.FullName" /> , or <see langword="null" /> if this <see cref="T:System.IO.FileSystemInfo" /> instance doesn't represent a link.
public
UnixFileMode
UnixFileMode
Gets or sets the Unix file mode for the current file or directory.
Methods
public
void
Create​()
Creates a directory.
public
DirectoryInfo
CreateSubdirectory​(string path)
Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the <see cref="T:System.IO.DirectoryInfo" /> class.
Returns The last directory specified in <paramref name="path" /> .
path
The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name.
public
void
Delete​()
Deletes this <see cref="T:System.IO.DirectoryInfo" /> if it is empty.
public
void
Delete​(bool recursive)
Deletes this instance of a <see cref="T:System.IO.DirectoryInfo" /> , specifying whether to delete subdirectories and files.
recursive
<see langword="true" /> to delete this directory, its subdirectories, and all files; otherwise, <see langword="false" /> .
public
Collections.​Generic.​IEnumerable<​DirectoryInfo>
EnumerateDirectories​()
Returns an enumerable collection of directory information in the current directory.
Returns An enumerable collection of directories in the current directory.
public
Collections.​Generic.​IEnumerable<​DirectoryInfo>
EnumerateDirectories​(string searchPattern)
Returns an enumerable collection of directory information that matches a specified search pattern.
Returns An enumerable collection of directories that matches <paramref name="searchPattern" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
public
Collections.​Generic.​IEnumerable<​DirectoryInfo>
EnumerateDirectories​(string searchPattern,
EnumerationOptions enumerationOptions)
Returns an enumerable collection of directory information that matches the specified search pattern and enumeration options.
Returns An enumerable collection of directories that matches <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
enumerationOptions
An object that describes the search and enumeration configuration to use.
public
Collections.​Generic.​IEnumerable<​DirectoryInfo>
EnumerateDirectories​(string searchPattern,
SearchOption searchOption)
Returns an enumerable collection of directory information that matches a specified search pattern and search subdirectory option.
Returns An enumerable collection of directories that matches <paramref name="searchPattern" /> and <paramref name="searchOption" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
searchOption
One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories. The default value is <see cref="F:System.IO.SearchOption.TopDirectoryOnly" /> .
public
Collections.​Generic.​IEnumerable<​FileInfo>
EnumerateFiles​()
Returns an enumerable collection of file information in the current directory.
Returns An enumerable collection of the files in the current directory.
public
Collections.​Generic.​IEnumerable<​FileInfo>
EnumerateFiles​(string searchPattern)
Returns an enumerable collection of file information that matches a search pattern.
Returns An enumerable collection of files that matches <paramref name="searchPattern" /> .
searchPattern
The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
public
Collections.​Generic.​IEnumerable<​FileInfo>
EnumerateFiles​(string searchPattern,
EnumerationOptions enumerationOptions)
Returns an enumerable collection of file information that matches the specified search pattern and enumeration options.
Returns An enumerable collection of files that matches <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
searchPattern
The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
enumerationOptions
An object that describes the search and enumeration configuration to use.
public
Collections.​Generic.​IEnumerable<​FileInfo>
EnumerateFiles​(string searchPattern,
SearchOption searchOption)
Returns an enumerable collection of file information that matches a specified search pattern and search subdirectory option.
Returns An enumerable collection of files that matches <paramref name="searchPattern" /> and <paramref name="searchOption" /> .
searchPattern
The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
searchOption
One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories. The default value is <see cref="F:System.IO.SearchOption.TopDirectoryOnly" /> .
public
Collections.​Generic.​IEnumerable<​FileSystemInfo>
EnumerateFileSystemInfos​()
Returns an enumerable collection of file system information in the current directory.
Returns An enumerable collection of file system information in the current directory.
public
Collections.​Generic.​IEnumerable<​FileSystemInfo>
EnumerateFileSystemInfos​(string searchPattern)
Returns an enumerable collection of file system information that matches a specified search pattern.
Returns An enumerable collection of file system information objects that matches <paramref name="searchPattern" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
public
Collections.​Generic.​IEnumerable<​FileSystemInfo>
EnumerateFileSystemInfos​(string searchPattern,
EnumerationOptions enumerationOptions)
Returns an enumerable collection of file system information that matches the specified search pattern and enumeration options.
Returns An enumerable collection of file system information objects that matches <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
enumerationOptions
An object that describes the search and enumeration configuration to use.
public
Collections.​Generic.​IEnumerable<​FileSystemInfo>
EnumerateFileSystemInfos​(string searchPattern,
SearchOption searchOption)
Returns an enumerable collection of file system information that matches a specified search pattern and search subdirectory option.
Returns An enumerable collection of file system information objects that matches <paramref name="searchPattern" /> and <paramref name="searchOption" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
searchOption
One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories. The default value is <see cref="F:System.IO.SearchOption.TopDirectoryOnly" /> .
public
DirectoryInfo[]
GetDirectories​()
Returns the subdirectories of the current directory.
Returns An array of <see cref="T:System.IO.DirectoryInfo" /> objects.
public
DirectoryInfo[]
GetDirectories​(string searchPattern)
Returns an array of directories in the current <see cref="T:System.IO.DirectoryInfo" /> matching the given search criteria.
Returns An array of type <see langword="DirectoryInfo" /> matching <paramref name="searchPattern" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
public
DirectoryInfo[]
GetDirectories​(string searchPattern,
EnumerationOptions enumerationOptions)
Returns an array of directories in the current <see cref="T:System.IO.DirectoryInfo" /> matching the specified search pattern and enumeration options.
Returns An array of type <see langword="DirectoryInfo" /> matching <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
enumerationOptions
An object that describes the search and enumeration configuration to use.
public
DirectoryInfo[]
GetDirectories​(string searchPattern,
SearchOption searchOption)
Returns an array of directories in the current <see cref="T:System.IO.DirectoryInfo" /> matching the given search criteria and using a value to determine whether to search subdirectories.
Returns An array of type <see langword="DirectoryInfo" /> matching <paramref name="searchPattern" /> .
searchPattern
The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
searchOption
One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories.
Returns An array of type <see cref="T:System.IO.FileInfo" /> .
public
FileInfo[]
GetFiles​(string searchPattern)
Returns a file list from the current directory matching the given search pattern.
Returns An array of type <see cref="T:System.IO.FileInfo" /> .
searchPattern
The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
public
FileInfo[]
GetFiles​(string searchPattern,
EnumerationOptions enumerationOptions)
Returns a file list from the current directory matching the specified search pattern and enumeration options.
Returns An array of strongly typed <see cref="T:System.IO.FileInfo" /> objects that match <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
searchPattern
The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
enumerationOptions
An object that describes the search and enumeration configuration to use.
public
FileInfo[]
GetFiles​(string searchPattern,
SearchOption searchOption)
Returns a file list from the current directory matching the given search pattern and using a value to determine whether to search subdirectories.
Returns An array of type <see cref="T:System.IO.FileInfo" /> .
searchPattern
The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
searchOption
One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories.
public
FileSystemInfo[]
GetFileSystemInfos​()
Returns an array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> entries representing all the files and subdirectories in a directory.
Returns An array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> entries.
public
FileSystemInfo[]
GetFileSystemInfos​(string searchPattern)
Retrieves an array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> objects representing the files and subdirectories that match the specified search criteria.
Returns An array of strongly typed <see langword="FileSystemInfo" /> objects matching the search criteria.
searchPattern
The search string to match against the names of directories and files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
public
FileSystemInfo[]
GetFileSystemInfos​(string searchPattern,
EnumerationOptions enumerationOptions)
Retrieves an array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> objects representing the files and subdirectories that match the specified search pattern and enumeration options.
Returns An array of strongly typed <see langword="FileSystemInfo" /> objects matching <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
searchPattern
The search string to match against the names of directories and files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
enumerationOptions
An object that describes the search and enumeration configuration to use.
public
FileSystemInfo[]
GetFileSystemInfos​(string searchPattern,
SearchOption searchOption)
Retrieves an array of <see cref="T:System.IO.FileSystemInfo" /> objects that represent the files and subdirectories matching the specified search criteria.
Returns An array of file system entries that match the search criteria.
searchPattern
The search string to match against the names of directories and files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.
searchOption
One of the enumeration values that specifies whether the search operation should include only the current directory or all subdirectories. The default value is <see cref="F:System.IO.SearchOption.TopDirectoryOnly" /> .
public
void
MoveTo​(string destDirName)
Moves a <see cref="T:System.IO.DirectoryInfo" /> instance and its contents to a new path.
destDirName
The name and path to which to move this directory. The destination cannot be another disk volume or a directory with the identical name. It can be an existing directory to which you want to add this directory as a subdirectory.
public
void
CreateAsSymbolicLink​(string pathToTarget)
Inherited from FileSystemInfo
Creates a symbolic link located in <see cref="P:System.IO.FileSystemInfo.FullName" /> that points to the specified <paramref name="pathToTarget" /> .
pathToTarget
The path of the symbolic link target.
public
void
GetObjectData​(Runtime.​Serialization.​SerializationInfo info,
Runtime.​Serialization.​StreamingContext context)
Inherited from FileSystemInfo
Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the file name and additional exception information.
info
The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.
context
The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.
public
void
Refresh​()
Inherited from FileSystemInfo
Refreshes the state of the object.
public
FileSystemInfo
ResolveLinkTarget​(bool returnFinalTarget)
Inherited from FileSystemInfo
Gets the target of the specified link.
Returns A <see cref="T:System.IO.FileSystemInfo" /> instance if the link exists, independently if the target exists or not; <see langword="null" /> if this file or directory is not a link.
returnFinalTarget
<see langword="true" /> to follow links to the final target; <see langword="false" /> to return the immediate next link.
public
string
ToString​()
Inherited from FileSystemInfo
Returns the original path. Use the <see cref="P:System.IO.FileSystemInfo.FullName" /> or <see cref="P:System.IO.FileSystemInfo.Name" /> properties for the full path or file/directory name.
Returns A string with the original path.
public
object
GetLifetimeService​()
Inherited from MarshalByRefObject
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance.
public
object
InitializeLifetimeService​()
Inherited from MarshalByRefObject
Obtains a lifetime service object to control the lifetime policy for this instance.
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime" /> property.
protected
MarshalByRefObject
MemberwiseClone​(bool cloneIdentity)
Inherited from MarshalByRefObject
Creates a shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
Returns A shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
cloneIdentity
<see langword="false" /> to delete the current <see cref="T:System.MarshalByRefObject" /> object's identity, which will cause the object to be assigned a new identity when it is marshaled across a remoting boundary. A value of <see langword="false" /> is usually appropriate. <see langword="true" /> to copy the current <see cref="T:System.MarshalByRefObject" /> object's identity to its clone, which will cause remoting client calls to be routed to the remote server object.
public
bool
Equals​(object obj)
Inherited from object
Determines whether the specified object is equal to the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
obj
The object to compare with the current object.
protected
void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public
int
GetHashCode​()
Inherited from object
Serves as the default hash function.
Returns A hash code for the current object.
public
Type
GetType​()
Inherited from object
Gets the <see cref="T:System.Type" /> of the current instance.
Returns The exact runtime type of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Creates a shallow copy of the current <see cref="T:System.Object" /> .
Returns A shallow copy of the current <see cref="T:System.Object" /> .