Skip to contents

get_file_size() returns the sizes of files in bytes. It works with local files and URLs.

Usage

get_file_size(file)

Arguments

file

A character vector of file paths. The function also works with URLs.

Value

A fs_bytes vector of file sizes.

See also

Other file functions: download_file()

Examples

library(fs)
library(readr)
#> 
#> Attaching package: ‘readr’
#> The following object is masked from ‘package:curl’:
#> 
#>     parse_date

files <- c("file1.txt", "file2.txt", "file3.txt")

dir <- tempfile("dir")
dir.create(dir)

for (i in files) {
  write_lines(rep(letters, sample(1000:10000, 1)), file.path(dir, i))
}

urls <- c(
  paste0(
    "https://geodata.ucdavis.edu/climate/worldclim/2_1/base/",
    "wc2.1_2.5m_tavg.zip"
  ),
  paste0(
    "https://geodata.ucdavis.edu/climate/worldclim/2_1/base/",
    "wc2.1_10m_prec.zip"
  )
)

c(urls, path(dir, files)) |> get_file_size()
#> 422.69M   6.92M 319.52K 331.4K 386.09K