Skip to contents

vsi_read_dir() abstracts access to directory contents. It returns a character vector containing the names of files and directories in this directory. This function is a wrapper for VSIReadDirEx() in the GDAL Common Portability Library.

Usage

vsi_read_dir(path, max_files = 0L)

Arguments

path

Character string. The relative or absolute path of a directory to read.

max_files

Integer scalar. The maximum number of files after which to stop, or 0 for no limit (see Note).

Value

A character vector containing the names of files and directories in the directory given by path. An empty string ("") is returned if path does not exist.

Note

If max_files is set to a positive number, directory listing will stop after that limit has been reached. Note that to indicate truncation, at least one element more than the max_files limit will be returned. If the length of the returned character vector is lesser or equal to max_files, then no truncation occurred.

Examples

# for illustration only
# this would normally be used with GDAL virtual file systems
data_dir <- system.file("extdata", package="gdalraster")
vsi_read_dir(data_dir)
#>  [1] "storm_lake.lcp"           "storml_evt.tif"          
#>  [3] "storml_tcc.tif"           "LF20_EVC_220.csv"        
#>  [5] ".."                       "test.geojson"            
#>  [7] "sr_b6_20200829.tif"       "ynp_fires_1984_2022.gpkg"
#>  [9] "storml_evh.tif"           "storml_pts.csv"          
#> [11] "LF20_EVH_220.csv"         "LF20_EVT_220.csv"        
#> [13] "."                        "int64.tif"               
#> [15] "storml_elev.tif"          "metadata.zip"            
#> [17] "sr_b4_20200829.tif"       "storm_lake.prj"          
#> [19] "LF20_F40_220.csv"         "sr_b5_20200829.tif"      
#> [21] "storml_evc.tif"