我目录中的文件很少(C:\ MY_FOLDER\Freeze).让我们说我有两个文件的日期时间前面.如下所示 :
我必须阅读R中最新的文件.请帮帮我.我试着寻找答案,但到处都是关于Linux系统的."ctime"和"mtime"在这里不起作用.
Ron*_*hah 20
我们可以使用file.info同list.files.list.files将列出感兴趣的目录中的所有文件,并file.info提供所有这些文件的详细信息.然后,我们使用which.maxon 获取最近修改的文件mtime,然后获取该文件的相应路径.
df <- file.info(list.files("/path/to/your/directory", full.names = T))
rownames(df)[which.max(df$mtime)]
#[1] "/path/to/your/directory/Interested_file.xlsx"
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用任何命令从该路径读取csv或excel.
另一种识别目录中最新文件的方法:
tmpshot <- fileSnapshot("/path/to/your/directory")
rownames(tmpshot$info[which.max(tmpshot$info$mtime),])
Run Code Online (Sandbox Code Playgroud)