Suppose I have many PDF files in ./reports, where all the file names start with my-report then date. For example, my-report-20200901.pdf.
./reports
my-report
my-report-20200901.pdf
doc
doc-20200901.pdf
20200901.pdf
You could be interested in fs for file manipulation.
There should be a renaming function.
You can use regex with grep or gsub, or stringr to do the file replacement; stringr::str_replace or stringr::str_remove for example
grep
gsub
stringr
stringr::str_replace
stringr::str_remove
This should be what is needed for this kind of task.
Here is a solution which should work cross-platform.
old <- dir("./reports", "my-report.*\\.pdf", full.names = TRUE, ignore.case = TRUE) file.rename(old, gsub("my-report", "doc", old))
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.