Home > Mobile >  Reneme files in R - Delete a section of the name
Reneme files in R - Delete a section of the name

Time:03-16

I have several files in a folder, named:

cbf485_f_p1_Reflection__4__29.txt

cbf485_f_p2_Reflection__2__32.txt

cbf4166_m_p2_Reflection__1__41.txt

nkm2801_m_p6_Reflection__4__139.txt

and so on.

I want to erase the last part of the name from each file, obtaining:

cbf485_f_p1_Reflection__4.txt

cbf485_f_p2_Reflection__2.txt

cbf4166_m_p2_Reflection__1.txt

nkm2801_m_p6_Reflection__4.txt

using R. R is life.

Any suggestion?

Thanks in advance!

CodePudding user response:

mapply(file.rename, filenames, sub("__\\d \\.", ".", filenames))

  •  Tags:  
  • r
  • Related