vsi_read_dir()
abstracts access to directory contents. It returns a
character vector containing the names of files and directories in this
directory. With recursive = TRUE
, reads the list of entries in the
directory and subdirectories.
This function is a wrapper for VSIReadDirEx()
and VSIReadDirRecursive()
in the GDAL Common Portability Library.
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). Ignored if
recursive = TRUE
.- recursive
Logical scalar.
TRUE
to read the directory and its subdirectories. Defaults toFALSE
.- all_files
Logical scalar. If ‘FALSE’ (the default), only the names of visible files are returned (following Unix-style visibility, that is files whose name does not start with a dot). If ‘TRUE’, all file names will be returned.
Value
A character vector containing the names of files and directories
in the directory given by path
. The listing is in alphabetical order, and
does not include the special entries '.' and '..' even if they are present
in the directory. 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. The max_files
parameter is ignored when
recursive = TRUE
.
Examples
# regular file system for illustration
data_dir <- system.file("extdata", package="gdalraster")
vsi_read_dir(data_dir)
#> [1] "LF20_EVC_220.csv" "LF20_EVH_220.csv"
#> [3] "LF20_EVT_220.csv" "LF20_F40_220.csv"
#> [5] "int64.tif" "metadata.zip"
#> [7] "poly_multipoly.dbf" "poly_multipoly.prj"
#> [9] "poly_multipoly.shp" "poly_multipoly.shx"
#> [11] "sr_b4_20200829.tif" "sr_b5_20200829.tif"
#> [13] "sr_b6_20200829.tif" "storm_lake.lcp"
#> [15] "storm_lake.prj" "storml_elev.tif"
#> [17] "storml_evc.tif" "storml_evh.tif"
#> [19] "storml_evt.tif" "storml_pts.csv"
#> [21] "storml_tcc.tif" "test.geojson"
#> [23] "ynp_fires_1984_2022.gpkg"