0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

#01 ファイルをまとめてリネーム(R、RStadio)

Last updated at Posted at 2022-06-29

ファイルをまとめてリネーム

多数のファイルをまとめてリネームしたいときに利用できるコードです。

①ファイルリストの作成

rename.R
# wdの設定(リネームしたいファイルがあるフォルダのパス)
setwd("hogehoge")
getwd()

# ファイル名の取得をして、ファイルリストを作成
write.csv(list.files(), 'list.csv')

②変更後のファイル名

①で作成したファイルリストに変更後のファイル名を追加する。

③リネームの実施

データフレームで変更前のファイル名と変更後のファイル名を入れて、
for文で回していく。

rename.R
# データフレームの読み込み
df <- read.csv("list.csv")

for (i in 1:nrow(df)) {
  file.rename(df[i,2],df[i,3])
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?