I searched and found stuff, but still having issues.
I have files in a directory "result (1).xlsx" and "result (2).xlsx". I want to change them to "new1.csv" and "new2.csv", etc.
I'm using the following and its not working (the problem seems to be regex.. and ive flip flopped between using just file.rename and sapply):
folder = "r:\\files"
files <- list.files(folder,pattern = "*.xlsx",full.names = T)
sapply(files,FUN=function(eachPath){
file.rename(from=eachPath,to= sub(pattern="result\\s(*).xlsx",
paste0("new.csv"),eachPath))
})
Thanks