Collapse AllExpand All      Code: All Code: Multiple Code: Visual Basic Code: C# Code: Visual C++ Code: F# Code: JScript 
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.

Namespace:   System.IO
Assembly:  System.IO (in System.IO.dll)
<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.

  NameDescription
Public method FileInfoInitializes a new instance of the FileInfo class, which acts as a wrapper for a file path.
Top
  NameDescription
Public property AttributesGets or sets the attributes for the current file or directory. (Inherited from FileSystemInfo.)
Public property CreationTimeGets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.)
Public property CreationTimeUtcGets or sets the creation time, in coordinated universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.)
Public property DirectoryGets an instance of the parent directory.
Public property DirectoryNameGets a string representing the directory's full path.
Public property ExistsGets a value indicating whether a file exists. (Overrides FileSystemInfo..::..Exists.)
Public property ExtensionGets the string representing the extension part of the file. (Inherited from FileSystemInfo.)
Public property FullNameGets the full path of the directory or file. (Inherited from FileSystemInfo.)
Public property LastAccessTimeGets or sets the time the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public property LastAccessTimeUtcGets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public property LastWriteTimeGets or sets the time when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public property LastWriteTimeUtcGets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public property LengthGets the size, in bytes, of the current file.
Public property NameGets the name of the file. (Overrides FileSystemInfo..::..Name.)
Top
  NameDescription
Public method CreateCreates a file.
Public method DeletePermanently deletes a file. (Overrides FileSystemInfo..::..Delete()()()().)
Public method Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public method GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method RefreshRefreshes the state of the object. (Inherited from FileSystemInfo.)
Public method ToStringReturns the path as a string. (Overrides Object..::..ToString()()()().)
Top

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.