Skip to content

List files in storage (similar to list.files())

Lists blob files available via a storage handler created by [init_storage_handler()(init_storage_handler/) and returns their names, optionally filtered by directory (path) and a filename pattern.

list_blob_files(handler, path = NULL, pattern = NULL, full.names = TRUE)
Argument Description
handler A Python object of class StorageHandler.
path Optional character string. Restrict results to blobs directly under this directory.
pattern Optional regular expression. Only file names matching this pattern are returned. Matching is applied to the basename, not the full path.
full.names Logical; if TRUE (default), return full blob paths. If FALSE, return only file names.

A character vector of blob names (paths or file names).

This function mimics the behaviour of base::list.files():

  • path filters blobs by their parent directory
  • pattern is applied to the file name (not the full path)
  • full.names controls whether full blob paths or only file names are returned

Internally, this function uses handler$list_blobs() and extracts the name field from each blob.

handler <- init_storage_handler(env = "local")
# all files
list_blob_files(handler)
# files in a directory
list_blob_files(handler, path = "SAMPLE")
# filter by pattern
list_blob_files(
handler,
path = "SAMPLE",
pattern = "^SAMPLE_(MONTHLY|YEARLY).*\\.csv$"
)
# only file names
list_blob_files(handler, path = "SAMPLE", full.names = FALSE)