使用列中的信息重命名多个 csv 文件名

发布于 2025-01-09 16:01:47 字数 361 浏览 2 评论 0原文

有许多老师在csv列中填写了他们的信息,但是,这些csv文件被标记为不规则的名称(例如,1.csv、apple school.csv、003.csv等)。

这些文件包含相同的列(id、分数、年级、班级、学校、城市)

在此处输入图像描述

我想用常规方式重命名 csv 文件,并一次性使用它们在列中填写的内容, 例如“1A_S_L.csv” 那么我就认出这个文件是来自L市S学校1A的老师

非常感谢您的帮助。

There are many teachers filled their information in the csv columns, however, these csv files were labelled with a irregular name (e.g., 1.csv, apple school.csv, 003.csv, etc.).

These files contain the same columns (id, score, grade,class, school, city)

enter image description here

I'd like to rename the csv files in a regular way with what they filled in the columns in one go, such as "1A_S_L.csv"
then I can recognize this file is from the teacher of 1A, S school, L city

Many thanks for your assistance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻身的咸鱼 2025-01-16 16:01:47

将输入文件放入名为 in 的文件夹中,创建一个名为 out 的空文件夹。
然后类似这样的事情将循环 in 中的文件,并将它们复制到 out 中的文件,其名称基于 gradeclass学校城市

for (file_in in dir("in", full.names = TRUE)) {
  df <- read.csv(file_in)
  filename <- paste(df[1,"grade"], df[1,"class"], df[1,"school"], df[1,"city"], sep = "_")
  file_out <- paste0("out/", filename, ".csv")
  print(file_out)
  write.csv(df, file_out)
}

Place your input files in a folder named in, create an empty folder named out.
Then something like this will loop over the files in in, and copy them to files in out with names based on grade, class, school and city:

for (file_in in dir("in", full.names = TRUE)) {
  df <- read.csv(file_in)
  filename <- paste(df[1,"grade"], df[1,"class"], df[1,"school"], df[1,"city"], sep = "_")
  file_out <- paste0("out/", filename, ".csv")
  print(file_out)
  write.csv(df, file_out)
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文