Skip to content
Prev 371581 / 398506 Next

rename multiple files by file.rename or other functions

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 renames
for ( s in v ) { file.rename(sub("--",s,strIn), sub("--",s,strOut) ) }

HTH,
Eric
On Thu, Sep 28, 2017 at 1:25 PM, Jim Lemon <drjimlemon at gmail.com> wrote: