FileInfo Class
Namespace: System.IO
Assembly: System.IO.FileSystem.dll (in System.IO.FileSystem.dll)
Summary:
Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in their creation.
The FileInfo class provides an instance property for creating and managing single files in a file system. It is used to create file streams, get file attributes, and perform various file operations on a specific file.
Constructors
| Name | Description |
|---|---|
| FileInfo(String fileName) | Initializes a new instance of the FileInfo class. |
| FileInfo(String fileName, Boolean ignoreCase) | Initializes a new instance of the FileInfo class with the specified file name, optionally specifying whether to ignore case. |
Properties
| Name | Description |
|---|---|
| Attributes | Gets or sets the attributes of the current file. |
| CreationTime | Gets the creation time of the current file or directory. |
| CreationTimeUtc | Gets the creation time, in Coordinated Universal Time (UTC), of the current file or directory. |
| Directory | Gets an instance of the parent directory. |
| DirectoryName | Gets the name of the parent directory. |
| Exists | Gets a value indicating whether the file exists. |
| Extension | Gets the extension of the file name that includes the period (e.g., ".txt"). |
| FullName | Gets the fully qualified path of the file or directory. |
| IsReadOnly | Gets or sets a value indicating whether the file is read-only. |
| LastAccessTime | Gets the date and time that the current file or directory was last accessed. |
| LastAccessTimeUtc | Gets the date and time, in Coordinated Universal Time (UTC), that the current file or directory was last accessed. |
| LastWriteTime | Gets or sets the date and time that the current file or directory was last written. |
| LastWriteTimeUtc | Gets or sets the date and time, in Coordinated Universal Time (UTC), that the current file or directory was last written. |
| Length | Gets the size, in bytes, of the current file. |
| Name | Gets the name of the file or directory. |
Methods
| Name | Description |
|---|---|
| CopyTo(String destFileName) | Copies an existing file to a new location. |
| CopyTo(String destFileName, Boolean overwrite) | Copies an existing file to a new location, with an option to overwrite an existing file. |
| Create() | Creates a new file. |
| Delete() | Deletes this file. |
| GetContents() | Gets the contents of the file. |
| MoveTo(String destFileName) | Moves an existing file to a new location. |
| Open(FileStreamMode mode) | Opens a file with read/write access. |
| OpenRead() | Opens an existing file for reading. |
| OpenText() | Opens a FileStream with read/write access to the file, specifying the path of the file to open. |
| OpenWrite() | Opens a file for writing UTF-8 encoded text. |
| Replace(String destinationFileName, String destinationBackupFileName) | Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file. |
| Replace(String destinationFileName, String destinationBackupFileName, Boolean ignoreMetadataErrors) | Replaces the contents of a specified file with the contents of another file, deleting the original file, and optionally creating a backup of the replaced file. |