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
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)
path
The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name.
Returns The last directory specified in <paramref name="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.
public
void
Delete​()
Deletes this <see cref="T:System.IO.DirectoryInfo" /> if it is empty.
public
void
Delete​(bool recursive)
recursive
<see langword="true" /> to delete this directory, its subdirectories, and all files; otherwise, <see langword="false" /> .
Deletes this instance of a <see cref="T:System.IO.DirectoryInfo" /> , specifying whether to delete subdirectories and files.
EnumerateDirectories​()
Returns An enumerable collection of directories in the current directory.
Returns an enumerable collection of directory information in the current directory.
EnumerateDirectories​(string 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.
Returns An enumerable collection of directories that matches <paramref name="searchPattern" /> .
Returns an enumerable collection of directory information that matches a specified search pattern.
EnumerateDirectories​(string searchPattern,
EnumerationOptions 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.
Returns An enumerable collection of directories that matches <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
Returns an enumerable collection of directory information that matches the specified search pattern and enumeration options.
EnumerateDirectories​(string searchPattern,
SearchOption 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" /> .
Returns An enumerable collection of directories that matches <paramref name="searchPattern" /> and <paramref name="searchOption" /> .
Returns an enumerable collection of directory information that matches a specified search pattern and search subdirectory option.
EnumerateFiles​()
Returns An enumerable collection of the files in the current directory.
Returns an enumerable collection of file information in the current directory.
EnumerateFiles​(string 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.
Returns An enumerable collection of files that matches <paramref name="searchPattern" /> .
Returns an enumerable collection of file information that matches a search pattern.
EnumerateFiles​(string searchPattern,
EnumerationOptions 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.
Returns An enumerable collection of files that matches <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
Returns an enumerable collection of file information that matches the specified search pattern and enumeration options.
EnumerateFiles​(string searchPattern,
SearchOption 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" /> .
Returns An enumerable collection of files that matches <paramref name="searchPattern" /> and <paramref name="searchOption" /> .
Returns an enumerable collection of file information that matches a specified search pattern and search subdirectory option.
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.
EnumerateFileSystemInfos​(string 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.
Returns An enumerable collection of file system information objects that matches <paramref name="searchPattern" /> .
Returns an enumerable collection of file system information that matches a specified search pattern.
EnumerateFileSystemInfos​(string searchPattern,
EnumerationOptions 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.
Returns An enumerable collection of file system information objects that matches <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
Returns an enumerable collection of file system information that matches the specified search pattern and enumeration options.
EnumerateFileSystemInfos​(string searchPattern,
SearchOption 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" /> .
Returns An enumerable collection of file system information objects that matches <paramref name="searchPattern" /> and <paramref name="searchOption" /> .
Returns an enumerable collection of file system information that matches a specified search pattern and search subdirectory option.
public
DirectoryInfo[]
GetDirectories​() Returns An array of <see cref="T:System.IO.DirectoryInfo" /> objects.
Returns the subdirectories of the current directory.
public
DirectoryInfo[]
GetDirectories​(string 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.
Returns An array of type <see langword="DirectoryInfo" /> matching <paramref name="searchPattern" /> .
Returns an array of directories in the current <see cref="T:System.IO.DirectoryInfo" /> matching the given search criteria.
public
DirectoryInfo[]
GetDirectories​(string searchPattern,
EnumerationOptions 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.
Returns An array of type <see langword="DirectoryInfo" /> matching <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
Returns an array of directories in the current <see cref="T:System.IO.DirectoryInfo" /> matching the specified search pattern and enumeration options.
public
DirectoryInfo[]
GetDirectories​(string searchPattern,
SearchOption 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.
Returns An array of type <see langword="DirectoryInfo" /> matching <paramref name="searchPattern" /> .
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.
public
FileInfo[]
GetFiles​() Returns An array of type <see cref="T:System.IO.FileInfo" /> .
Returns a file list from the current directory.
public
FileInfo[]
GetFiles​(string 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.
Returns An array of type <see cref="T:System.IO.FileInfo" /> .
Returns a file list from the current directory matching the given search pattern.
public
FileInfo[]
GetFiles​(string searchPattern,
EnumerationOptions 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.
Returns An array of strongly typed <see cref="T:System.IO.FileInfo" /> objects that match <paramref name="searchPattern" /> and <paramref name="enumerationOptions" /> .
Returns a file list from the current directory matching the specified search pattern and enumeration options.
public
FileInfo[]
GetFiles​(string searchPattern,
SearchOption 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.
Returns An array of type <see cref="T:System.IO.FileInfo" /> .
Returns a file list from the current directory matching the given search pattern and using a value to determine whether to search subdirectories.
public
FileSystemInfo[]
GetFileSystemInfos​() Returns An array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> entries.
Returns an array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> entries representing all the files and subdirectories in a directory.
public
FileSystemInfo[]
GetFileSystemInfos​(string searchPattern)
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.
Returns An array of strongly typed <see langword="FileSystemInfo" /> objects matching the search criteria.
Retrieves an array of strongly typed <see cref="T:System.IO.FileSystemInfo" /> objects representing the files and subdirectories that match the specified search criteria.
public
FileSystemInfo[]
GetFileSystemInfos​(string searchPattern,
EnumerationOptions 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.
Returns An array of strongly typed <see langword="FileSystemInfo" /> objects matching <paramref name="searchPattern" /> and <paramref name="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.
public
FileSystemInfo[]
GetFileSystemInfos​(string searchPattern,
SearchOption searchOption)
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" /> .
Returns An array of file system entries that match the search criteria.
Retrieves an array of <see cref="T:System.IO.FileSystemInfo" /> objects that represent the files and subdirectories matching the specified search criteria.
public
void
MoveTo​(string destDirName)
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.
Moves a <see cref="T:System.IO.DirectoryInfo" /> instance and its contents to a new path.
public
void
CreateAsSymbolicLink​(string pathToTarget)
Inherited from FileSystemInfo
pathToTarget
The path of the symbolic link target.
Creates a symbolic link located in <see cref="P:System.IO.FileSystemInfo.FullName" /> that points to the specified <paramref name="pathToTarget" /> .
public
void
GetObjectData​(Runtime.Serialization.SerializationInfo info,
Runtime.Serialization.StreamingContext context)
Inherited from FileSystemInfo
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.
Sets the <see cref="T:System.Runtime.Serialization.SerializationInfo" /> object with the file name and additional exception information.
Refreshes the state of the object.
public
FileSystemInfo
ResolveLinkTarget​(bool returnFinalTarget)
Inherited from FileSystemInfo
returnFinalTarget
<see langword="true" /> to follow links to the final target; <see langword="false" /> to return the immediate next 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.
Gets the target of the specified link.
public
string
ToString​()
Inherited from FileSystemInfo
Returns A string with the original path.
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.
public
object
GetLifetimeService​()
Inherited from MarshalByRefObject
Returns An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease" /> used to control the lifetime policy for this instance.
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
public
object
InitializeLifetimeService​()
Inherited from MarshalByRefObject
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.
Obtains a lifetime service object to control the lifetime policy for this instance.
protected
MarshalByRefObject
MemberwiseClone​(bool cloneIdentity)
Inherited from MarshalByRefObject
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.
Returns A shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
Creates a shallow copy of the current <see cref="T:System.MarshalByRefObject" /> object.
public
bool
Equals​(object obj)
Inherited from object
obj
The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to 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
Returns A hash code for the current object.
Serves as the default hash function.
public
Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected
object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .