Logo

Programming-Idioms

  • Rust
  • Dart

Idiom #95 Get file size

Assign to variable x the length (number of bytes) of the local file at path.

var x = File(path).lengthSync();
import 'dart:io';
final x = (await File(path).readAsBytes()).length;
use std::path::Path;
let x = path.metadata()?.len();

path has type &std::path::Path
use std::fs;
use std::io;
use std::os::linux::fs::MetadataExt;
let x = fs::metadata(path)?.st_size();

Populated from stat
use std::fs;
let x = fs::metadata(path)?.len();
with Ada.Directories; use Ada.Directories;
X : constant File_Size := Size (Path);

New implementation...
< >
programming-idioms.org