regex - r rename files in folder from xlsx to csv -


this question has answer here:

i searched , found stuff, still having issues.

i have files in directory "result (1).xlsx" , "result (2).xlsx". want change them "new1.csv" , "new2.csv", etc.

i'm using following , not working (the problem seems regex.. , ive flip flopped between using file.rename , 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

before answer question, i'd mention changing extension of file doesn't, in computer science, automatically change file formatting. in other words, changing .xlsx .csv purpose of converting csv won't want.

instead, i'd recommend readxl package read xlsx files r. once in r, save table csv there if still needed. there many ways this, here's one:

install.packages("readxl")  library(readxl)  df <- read_excel("yourdata.xlsx")  #optional save/convert csv write.csv(df,"yourdata.csv",row.names=false) 

if you'd more info on how more on series of files, take @ answers so question on topic.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -