Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread Jim Lemon
Hi John, After a bit of thinking: # fill in the appropriate path and pattern filenames<-list.files(path=???,pattern=???) for(filename in filenames) { filefirst<-sapply(strsplit(filename,"[.]"),"[",1) # delete all non-digits fileno<-gsub("[^[:digit:]]","",filefirst)

Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread Thierry Onkelinx
The combination of list.files(), gsub() and file.rename() should to the trick. ir. Thierry Onkelinx Statisticus/ Statistician Vlaamse Overheid / Government of Flanders INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND FOREST Team Biometrie & Kwaliteitszorg / Team

Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread peter dalgaard
> On 28 Sep 2017, at 12:57 , Eric Berger wrote: > > Hi John, > Thanks to Jim for pointing out the file.rename() function. You can try this: > > # define the filename templates > strIn <- "XYZW--Genesis_ABC.mp3" > strOut <- "01Gen--.mp3" > > # create the strings "01",

Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread Eric Berger
Hi John, Thanks to Jim for pointing out the file.rename() function. You can try this: # define the filename templates strIn <- "XYZW--Genesis_ABC.mp3" strOut <- "01Gen--.mp3" # create the strings "01", "02", ..., "50" v <- sapply(1:50, function(i) sprintf("%02d",i) ) # perform all the file

Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread Jim Lemon
Hi John, Maybe this: filenames<-c("XYZW01Genesis_ABC.mp3","XYZW02Genesis_ABC.mp3") for(filename in filenames) { filefirst<-sapply(strsplit(filename,"[.]"),"[",1) fileno<-sub("_","",gsub("[[:alpha:]]","",filefirst)) file.rename(filename,paste("01Gen",fileno,".mp3",sep="")) } Jim On Thu, Sep

Re: [R] rename multiple files by file.rename or other functions

2017-09-28 Thread Ulrik Stervbo
Hi John, I don't know how to do this with R, but on Linux I'd use rename (or maybe even by hand if it's a one time event). On Windows I believe there is a tool called Bulk Rename. HTH Ulrik On Thu, 28 Sep 2017 at 11:37 John wrote: > Hi, > >I have 50 files whose names

[R] rename multiple files by file.rename or other functions

2017-09-28 Thread John
Hi, I have 50 files whose names are XYZW01Genesis_ABC.mp3 XYZW02Genesis_ABC.mp3 ... XYZW50Genesis_ABC.mp3 As you can tell, the only difference across the files are 01, 02, 03,50. I would like to rename them to 01Gen01.mp3 01Gen02.mp3 ... 01Gen50.mp3 If I store them in