Share via


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
Public method FileInfo Initializes a new instance of the FileInfo class, which acts as a wrapper for a file path.

Top

Properties

  Name Description
Public property Attributes Gets or sets the attributes for the current file or directory. (Inherited from FileSystemInfo.)
Public property CreationTime Gets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.)
Public property CreationTimeUtc Gets or sets the creation time, in coordinated universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.)
Public property Directory Gets an instance of the parent directory.
Public property DirectoryName Gets a string representing the directory's full path.
Public property Exists Gets a value indicating whether a file exists. (Overrides FileSystemInfo. . :: . .Exists.)
Public property Extension Gets the string representing the extension part of the file. (Inherited from FileSystemInfo.)
Public property FullName Gets the full path of the directory or file. (Inherited from FileSystemInfo.)
Public property LastAccessTime Gets or sets the time the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public property LastAccessTimeUtc Gets or sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public property LastWriteTime Gets or sets the time when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public property LastWriteTimeUtc Gets or sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public property Length Gets the size, in bytes, of the current file.
Public property Name Gets the name of the file. (Overrides FileSystemInfo. . :: . .Name.)

Top

Methods

  Name Description
Public method Create Creates a file.
Public method Delete Permanently 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 GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Refresh Refreshes the state of the object. (Inherited from FileSystemInfo.)
Public method 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.

See Also

Reference

System.IO Namespace