Skip to content

Instantly share code, notes, and snippets.

@fauxneticien
Created April 5, 2018 03:21
Show Gist options
  • Save fauxneticien/df270bd1196f8e7a0d8c1a9e156428ce to your computer and use it in GitHub Desktop.
Save fauxneticien/df270bd1196f8e7a0d8c1a9e156428ce to your computer and use it in GitHub Desktop.
Rename files with regex in R
library(purrr)
library(stringr)
list.files("~/git-repos/coedl/dbd/public/pdfs", pattern = "PDFsam", full.names = TRUE) %>%
walk(function(path) {
file.rename(
path,
str_replace(path, "(\\d+)_PDFsam_(dbd-[A-Z]+).pdf", "\\2_\\1.pdf")
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment