dir_contents: Summarise the contents of a directory

View source: R/dir_contents.R

dir_contentsR Documentation

Summarise the contents of a directory

Description

These functions give information about the size of directories as well as the number of files and sub-directories they contain (both in the immediate directory and recursively over sub-directories).

dir_contents() returns a data frame with rows for each directory or sub-directories.

dir_size(), dir_count_files() and dir_count_dirs() return atomic vectors of, respectively, the size, the number of files, and the number of directories in dir. All information returned by these functions is included in the output of dir_contents(), but they may be useful for simplicity or speed.

Usage

dir_contents(dir = ".", recurse = TRUE, ..., shorten = TRUE)

dir_size(dir = ".", recurse = TRUE, ...)

dir_count_files(dir = ".", recurse = TRUE, ...)

dir_count_dirs(dir = ".", recurse = TRUE, ...)

Arguments

dir

A character vector of directory paths. For dir_contents() this must be length one.

recurse

Passed to dir_info(). Defaults to TRUE so that all sub-directory contents are included. For dir_contents() this only effects which rows are included in the output, not how the counts or totals are calculated.

...

Additional arguments passed to dir_info().

shorten

If TRUE (default), the directory column gives the path relative to dir (the dir entry is displayed as "."). If FALSE, the full path is given.

Value

dir_size() returns an fs_bytes vector.

dir_count_files() and dir_count_dirs() each return integer vectors.

dir_contents() returns a data frame with columns:

directory

The path of the directory as an fs::path.

level

The level of the directory relative to dir.

total_size

The total size of all files in the directory, including sub-directories.

total_files

The total number of all files in the directory, including sub-directories.

total_dirs

The total number of all directories in the directory (fully recursive).

files_size

The total size of all files in the immediate directory (not sub-directories).

num_files

The number of files in the immediate directory.

num_dirs

The number of immediate sub-directories of the directory.

All size columns are fs_bytes numeric vectors.


jedwards24/edwards documentation built on Sept. 2, 2023, 8:16 a.m.