FileInfo Class
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Provides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited.
Inheritance Hierarchy
System. . :: . .Object
System. . :: . .MarshalByRefObject
System.IO. . :: . .FileSystemInfo
System.IO..::..FileInfo
Namespace: System.IO
Assembly: System.IO (in System.IO.dll)
Syntax
'Declaration
<SerializableAttribute> _
Public NotInheritable Class FileInfo _
Inherits FileSystemInfo
[SerializableAttribute]
public sealed class FileInfo : FileSystemInfo
[SerializableAttribute]
public ref class FileInfo sealed : public FileSystemInfo
[<Sealed>]
[<SerializableAttribute>]
type FileInfo =
class
inherit FileSystemInfo
end
public final class FileInfo extends FileSystemInfo
The FileInfo type exposes the following members.
Constructors
Name | Description | |
---|---|---|
FileInfo | Initializes a new instance of the FileInfo class, which acts as a wrapper for a file path. |
Top
Properties
Name | Description | |
---|---|---|
Attributes | Gets or sets the attributes for the current file or directory. (Inherited from FileSystemInfo.) | |
CreationTime | Gets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.) | |
CreationTimeUtc | Gets or sets the creation time, in coordinated universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.) | |
Directory | Gets an instance of the parent directory. | |
DirectoryName | Gets a string representing the directory's full path. | |
Exists | Gets a value indicating whether a file exists. (Overrides FileSystemInfo. . :: . .Exists.) | |
Extension | Gets the string representing the extension part of the file. (Inherited from FileSystemInfo.) | |
FullName | Gets the full path of the directory or file. (Inherited from FileSystemInfo.) | |
LastAccessTime | Gets or sets the time the current file or directory was last accessed. (Inherited from FileSystemInfo.) | |
LastAccessTimeUtc | Gets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.) | |
LastWriteTime | Gets or sets the time when the current file or directory was last written to. (Inherited from FileSystemInfo.) | |
LastWriteTimeUtc | Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.) | |
Length | Gets the size, in bytes, of the current file. | |
Name | Gets the name of the file. (Overrides FileSystemInfo. . :: . .Name.) |
Top
Methods
Name | Description | |
---|---|---|
Create | Creates a file. | |
Delete | Permanently deletes a file. (Overrides FileSystemInfo. . :: . .Delete() () () ().) | |
Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Refresh | Refreshes the state of the object. (Inherited from FileSystemInfo.) | |
ToString | Returns the path as a string. (Overrides Object. . :: . .ToString() () () ().) |
Top
Remarks
Use the FileInfo class for typical operations such as copying, moving, renaming, creating, opening, deleting, and appending to files.
If you are going to reuse an object several times, consider using the instance method of FileInfo instead of the corresponding static methods of the File class, because a security check will not always be necessary.
In members that accept a path, the path can refer to a file or just a directory. The specified path can also refer to a relative path or a Universal Naming Convention (UNC) path for a server and share name. For example, all the following are acceptable paths:
"c:\\MyDir\\MyFile.txt" in C#, or "c:\MyDir\MyFile.txt" in Visual Basic.
"c:\\MyDir" in C#, or "c:\MyDir" in Visual Basic.
"MyDir\\MySubdir" in C#, or "MyDir\MySubDir" in Visual Basic.
"\\\\MyServer\\MyShare" in C#, or "\\MyServer\MyShare" in Visual Basic.
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.