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.​FileInfo

Assembly: System.Runtime

Inheritance: object → MarshalByRefObjectFileSystemInfo → FileInfo

Provides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of <see cref="T:System.IO.FileStream" /> objects. 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 DirectoryInfo
Directory
Gets an instance of the parent directory.
public string
DirectoryName
Gets a string representing the directory's full path.
public bool
Exists
Gets a value indicating whether a file exists.
public bool
IsReadOnly
Gets or sets a value that determines if the current file is read only.
public long
Length
Gets the size, in bytes, of the current file.
public string
Name
Gets the name of the file.
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 StreamWriter
AppendText​()
Returns A new <see langword="StreamWriter" /> .
Creates a <see cref="T:System.IO.StreamWriter" /> that appends text to the file represented by this instance of the <see cref="T:System.IO.FileInfo" /> .
public FileInfo
CopyTo​(string destFileName)
destFileName The name of the new file to copy to.
Returns A new file with a fully qualified path.
Copies an existing file to a new file, disallowing the overwriting of an existing file.
public FileInfo
CopyTo​(string destFileName, bool overwrite)
destFileName The name of the new file to copy to.
overwrite <see langword="true" /> to allow an existing file to be overwritten; otherwise, <see langword="false" /> .
Returns A new file, or an overwrite of an existing file if <paramref name="overwrite" /> is <see langword="true" /> . If the file exists and <paramref name="overwrite" /> is <see langword="false" /> , an <see cref="T:System.IO.IOException" /> is thrown.
Copies an existing file to a new file, allowing the overwriting of an existing file.
public FileStream
Create​()
Returns A new file.
Creates a file.
public StreamWriter
CreateText​()
Returns A new <see langword="StreamWriter" /> .
Creates a <see cref="T:System.IO.StreamWriter" /> that writes a new text file.
public void
Decrypt​()
Decrypts a file that was encrypted by the current account using the <see cref="M:System.IO.FileInfo.Encrypt" /> method.
public void
Delete​()
Permanently deletes a file.
public void
Encrypt​()
Encrypts a file so that only the account used to encrypt the file can decrypt it.
public void
MoveTo​(string destFileName)
destFileName The path to move the file to, which can specify a different file name.
Moves a specified file to a new location, providing the option to specify a new file name.
public void
MoveTo​(string destFileName, bool overwrite)
destFileName The path to move the file to, which can specify a different file name.
overwrite <see langword="true" /> to overwrite the destination file if it already exists; <see langword="false" /> otherwise.
Moves a specified file to a new location, providing the options to specify a new file name and to overwrite the destination file if it already exists.
public FileStream
Open​(FileMode mode)
mode A <see cref="T:System.IO.FileMode" /> constant specifying the mode (for example, <see langword="Open" /> or <see langword="Append" /> ) in which to open the file.
Returns A file opened in the specified mode, with read/write access and unshared.
Opens a file in the specified mode.
public FileStream
Open​(FileMode mode, FileAccess access)
mode A <see cref="T:System.IO.FileMode" /> constant specifying the mode (for example, <see langword="Open" /> or <see langword="Append" /> ) in which to open the file.
access A <see cref="T:System.IO.FileAccess" /> constant specifying whether to open the file with <see langword="Read" /> , <see langword="Write" /> , or <see langword="ReadWrite" /> file access.
Returns A <see cref="T:System.IO.FileStream" /> object opened in the specified mode and access, and unshared.
Opens a file in the specified mode with read, write, or read/write access.
public FileStream
Open​(FileMode mode, FileAccess access, FileShare share)
mode A <see cref="T:System.IO.FileMode" /> constant specifying the mode (for example, <see langword="Open" /> or <see langword="Append" /> ) in which to open the file.
access A <see cref="T:System.IO.FileAccess" /> constant specifying whether to open the file with <see langword="Read" /> , <see langword="Write" /> , or <see langword="ReadWrite" /> file access.
share A <see cref="T:System.IO.FileShare" /> constant specifying the type of access other <see langword="FileStream" /> objects have to this file.
Returns A <see cref="T:System.IO.FileStream" /> object opened with the specified mode, access, and sharing options.
Opens a file in the specified mode with read, write, or read/write access and the specified sharing option.
public FileStream
Open​(FileStreamOptions options)
options An object that describes optional <see cref="T:System.IO.FileStream" /> parameters to use.
Returns A <see cref="T:System.IO.FileStream" /> that wraps the opened file.
Initializes a new instance of the <see cref="T:System.IO.FileStream" /> class with the specified creation mode, read/write and sharing permission, the access other FileStreams can have to the same file, the buffer size, additional file options and the allocation size.
public FileStream
OpenRead​()
Returns A new read-only <see cref="T:System.IO.FileStream" /> object.
Creates a read-only <see cref="T:System.IO.FileStream" /> .
public StreamReader
OpenText​()
Returns A new <see langword="StreamReader" /> with UTF8 encoding.
Creates a <see cref="T:System.IO.StreamReader" /> with UTF8 encoding that reads from an existing text file.
public FileStream
OpenWrite​()
Returns A write-only unshared <see cref="T:System.IO.FileStream" /> object for a new or existing file.
Creates a write-only <see cref="T:System.IO.FileStream" /> .
public FileInfo
Replace​(string destinationFileName, string destinationBackupFileName)
destinationFileName The name of a file to replace with the current file.
destinationBackupFileName The name of a file with which to create a backup of the file described by the <paramref name="destinationFileName" /> parameter.
Returns A <see cref="T:System.IO.FileInfo" /> object that encapsulates information about the file described by the <paramref name="destinationFileName" /> parameter.
Replaces the contents of a specified file with the file described by the current <see cref="T:System.IO.FileInfo" /> object, deleting the original file and creating a backup of the replaced file.
public FileInfo
Replace​(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors)
destinationFileName The name of a file to replace with the current file.
destinationBackupFileName The name of a file with which to create a backup of the file described by the <paramref name="destinationFileName" /> parameter.
ignoreMetadataErrors <see langword="true" /> to ignore merge errors (such as attributes and ACLs) from the replaced file to the replacement file; otherwise <see langword="false" /> .
Returns A <see cref="T:System.IO.FileInfo" /> object that encapsulates information about the file described by the <paramref name="destinationFileName" /> parameter.
Replaces the contents of a specified file with the file described by the current <see cref="T:System.IO.FileInfo" /> object, deleting the original file, and creating a backup of the replaced file. Also specifies whether to ignore merge errors.
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.
public void
Refresh​()
Inherited from FileSystemInfo
Refreshes the state of the object.
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" /> .