file.rename(from, to) smi <- list.files("G:\\\\襷", full.name=TRUE) f <- list.files("G:\\\\", full.name=FALSE)[1:75] for(i in 1:length(f)){ from <- smi[i] to <-paste0("G:\\\\襷\\", gsub(".mp4", ".smi", f[i])) file.rename(from, to) }