Skip to contents

This function takes a vector of file paths and returns a data frame with the file name and size of each file. File sizes can be reported in different units (bytes, kilobytes, megabytes, gigabytes). A file will have a size of NA if and only if, the file doesn't exists.

Usage

file_size(files, units = "bytes")

Arguments

files

A vector of file paths.

units

The desired file size unit: 'bytes' (the default), 'kb', 'mb', or 'gb'.

Value

A data frame with the following properties:

  • Has as many rows as files.

  • Has two columns: filename (identical to files) and size (in the desired units).

Examples

if (FALSE) {
file_size(c("file1.txt", "file2.txt"), units = 'kb')
}