Skip to contents

This function is equivalent to the Unix ls command but works across platforms. It can list files and directories matching a regular expression pattern.

Usage

ls_files(path = ".", regexp = NULL)

Arguments

path

A character vector of one or more paths to search

regexp

A regular expression pattern to filter files/directories

Value

A character vector of file and directory paths

Details

The function:

  • Handles both single and multiple paths

  • Supports regular expression filtering

  • Removes system-specific directories (e.g., @eaDir)

  • Returns full paths

Examples

# \donttest{
# List all files in current directory
org::ls_files()
#> [1] "/rpkg/docs/reference/cat_to_filepath_function_factory.html"      
#> [2] "/rpkg/docs/reference/create_project_quarto_external_results.html"
#> [3] "/rpkg/docs/reference/create_project_quarto_internal_results.html"
#> [4] "/rpkg/docs/reference/figures"                                    
#> [5] "/rpkg/docs/reference/index.html"                                 
#> [6] "/rpkg/docs/reference/initialize_project.html"                    
#> [7] "/rpkg/docs/reference/initialize_project_folders.html"            

# List only R files
org::ls_files(regexp = "\\.R$")
#> character(0)

# List files in multiple directories
org::ls_files(c("dir1", "dir2"))
#> [[1]]
#> character(0)
#> 
#> [[2]]
#> character(0)
#> 
# }