vsi_rename()
renames a file object in the file system. The GDAL
documentation states it should be possible to rename a file onto a new
filesystem, but it is safest if this function is only used to rename files
that remain in the same directory.
This function goes through the GDAL VSIFileHandler
virtualization and may
work on unusual filesystems such as in memory.
It is a wrapper for VSIRename()
in the GDAL Common Portability Library.
Analog of the POSIX rename()
function.
Arguments
- oldpath
Character string. The name of the file to be renamed.
- newpath
Character string. The name the file should be given.
Examples
# for illustration only
# this would normally be used with GDAL virtual file systems
elev_file <- system.file("extdata/storml_elev.tif", package="gdalraster")
tmp_file <- tempfile(fileext = ".tif")
file.copy(elev_file, tmp_file)
#> [1] TRUE
new_file <- file.path(dirname(tmp_file), "storml_elev_copy.tif")
result <- vsi_rename(tmp_file, new_file)
print(result)
#> [1] 0
vsi_unlink(new_file)