---
# System prepended metadata

title: 改檔案名稱
tags: [R教學, 基礎教學]

---

# 改檔案名稱
###### tags: `R教學` `基礎教學`

練習檔案資料夾：[file_name](https://drive.google.com/drive/folders/1C-zKtZOJYFelmtR-1B0Uq_zoBEE6fMfu?usp=sharing)

```r=
setwd(choose.dir())
#############
Location <- "file_name"
dir_name <- "test"   #####create a new folder 
lead_name <- "test"  #####

#############
file <- list.files (Location,full.names = T)
dir.create(dir_name)
file.copy(from = file, to = dir_name)
oldNames = list.files(dir_name, full.names = F)
newNames = paste(lead_name,formatC(1:length(file), width = 3, flag = "0") ,".JPG",sep="")
file.rename(from = file.path(dir_name, oldNames), 
            to = file.path(dir_name, newNames))

```