【发布时间】:2020-11-14 21:24:52
【问题描述】:
setwd("C:\\Users\\...\\Documents\\Main\\eml orders")
files <- list.files(pattern="*.eml")
newfiles <- gsub(".eml$", ".txt", files)
file.rename(files, newfiles)
eml_files <- list.files(pattern = "txt$")
我有这段代码可以将 .eml 转换为 .txt 文件,现在我想将相同的文件重命名为我使用函数创建的字符串。
函数示例
fetch_date <- function(x) {
date <- paste0(as.character(Sys.time()), ".txt")
file.rename(x, date)
}
现在我试试map(eml_files, fetch_date)
并得到这个错误:
cannot rename file '24 New order placed.txt' to '2020-11-14', reason 'The network path was not found'
不知道发生了什么任何帮助将不胜感激。
【问题讨论】:
-
你可能需要
full.names = TRUEinlist.files -
同样的错误:/ .
-
函数内部,可能需要用
file.path指定路径 -
我在函数内部做了
file.path("C:\\Users\\...\\Documents\\Main\\eml orders"),但它仍然无法正常工作。抛出相同的错误。 -
您的 file.rename 似乎在函数之外工作。你有没有试过不带函数的第二组重命名