You can do that like below: startingDir<-"/myDirectory" filez<-list.files(startingDir)
sapply(filez,FUN=function(eachPath){ file.rename(from=eachPath,to=sub(pattern="xxx",replacement="newTextString",eachPath)) }) On Mon, Feb 3, 2014 at 10:48 AM, arun <smartpink...@yahoo.com> wrote: > Hi, > Check ?file.rename() > http://stackoverflow.com/questions/10758965/how-do-i-rename-files-using-r > > > A.K. > > > I have list of files in folder > > e.g p126r62_5t19880613_nn1.tif.gz > p126r62_5t19880613_nn2.tif.gz > p200r65_5t19880613_nn1.tif.gz > > and I would like to change file name to > LT512606219880613XX_B1.tif.gz > LT512606219880613XX_B2.tif.gz > LT520006519880613XX_B1.tif.gz > > Does any body knows how It can be changed? > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Qiang Kou q...@umail.iu.edu School of Informatics and Computing, Indiana University [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.