Skip to content

[API Proposal]: System.IO.File.GetLength(string) #125240

@TonyValenti

Description

@TonyValenti

Background and motivation

Currently getting the size of a file requires creating a new instance of the FileInfo class and calling the Length instance method. This is clunky. A GetLength static method will be easier to use and pair nicely with existing Get(...) methods on System.IO.File.

API Proposal

namespace System.IO;

public static class File
{
    public static long GetLength(string path);
    public static long GetLength(SafeFileHandle fileHandle);
}

API Usage

// Fancy the value

var FileSize = Syste.IO.File.GetLength($@"C:\Text.txt");

Alternative Designs

Continue using FileInfo

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.IO

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions