file_extension()
Get the extension of a file.file_name()
Get the name of a file.file_dir()
Get or directory of a filemanipulate_files()
Manipulate files in a directory with options to rename (insert prefix or suffix) and save the new files to the same or other provided directory.pliman_indexes()
Get the indexes available in pliman.pliman_indexes_eq()
Get the equation of the indexes available in pliman.
Usage
file_extension(file)
file_name(file)
file_dir(file)
manipulate_files(
pattern,
dir = NULL,
prefix = NULL,
name = NULL,
suffix = NULL,
extension = NULL,
sep = "",
save_to = NULL,
overwrite = FALSE,
remove_original = FALSE,
verbose = TRUE
)
Arguments
- file
The file name.
- pattern
A file name pattern.
- dir
The working directory containing the files to be manipulated. Defaults to the current working directory.
- prefix, suffix
A prefix or suffix to be added in the new file names. Defaults to
NULL
(no prefix or suffix).- name
The name of the new files. Defaults to
NULL
(original names).name
can be either a single value or a character vector of the same length as the number of files manipulated. If one value is informed, a sequential vector of names will be created as "name
_1", "name
_2", and so on.- extension
The new extension of the file. If not declared (default), the original extensions will be used.
- sep
An optional separator. Defaults to
""
.- save_to
The directory to save the new files. Defaults to the current working directory. If the file name of a file is not changed, nothing will occur. If
save_to
refers to a subfolder in the current working directory, the files will be saved to the given folder. In case of the folder doesn't exist, it will be created. By default, the files will not be overwritten. Setoverwrite = TRUE
to overwrite the files.- overwrite
Overwrite the files? Defaults to
FALSE
.- remove_original
Remove original files after manipulation? defaults to
FALSE
. IfTRUE
the files inpattern
will be removed.- verbose
If
FALSE
, the code is run silently.
Value
file_extension()
,file_name()
, andfile_dir()
return a character string.manipulate_files()
No return value. Ifverbose == TRUE
, a message is printed indicating which operation succeeded (or not) for each of the files attempted.
Examples
# \donttest{
library(pliman)
# get file name, directory and extension
file <- "E:/my_folder/my_subfolder/image1.png"
file_dir(file)
file_name(file)
#> [1] "image1"
file_extension(file)
#> [1] "png"
# manipulate files
dir <- tempdir()
list.files(dir)
#> [1] "bslib-d8f79fa3acd9314074b3a3e3b7405d4b"
#> [2] "downlit"
#> [3] "file1eac1591a40"
#> [4] "file1eac5ad85327"
#> [5] "file1eac774f3dd4"
#> [6] "test.tif"
file.create(paste0(dir, "/test.txt"))
#> [1] TRUE
list.files(dir)
#> [1] "bslib-d8f79fa3acd9314074b3a3e3b7405d4b"
#> [2] "downlit"
#> [3] "file1eac1591a40"
#> [4] "file1eac5ad85327"
#> [5] "file1eac774f3dd4"
#> [6] "test.tif"
#> [7] "test.txt"
manipulate_files("test",
dir = paste0(dir, "\\"),
prefix = "chang_",
save_to = paste0(dir, "\\"),
overwrite = TRUE)
#> 2 files successfully copied to 'C:\Users\tiago\AppData\Local\Temp\Rtmpgfk9di\'
list.files(dir)
#> [1] "bslib-d8f79fa3acd9314074b3a3e3b7405d4b"
#> [2] "chang_test.tif"
#> [3] "chang_test.txt"
#> [4] "downlit"
#> [5] "file1eac1591a40"
#> [6] "file1eac5ad85327"
#> [7] "file1eac774f3dd4"
#> [8] "test.tif"
#> [9] "test.txt"
# }