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)
file.rename(filename,paste("
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 Biometr
> 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", "02", ..., "50"
> v <- sa
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 rena
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 28
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 are
>
> XYZW01Genesis_
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 on
7 matches
Mail list logo