[英]Determining age of a file in R
I'm trying to determine age of a file in R. Here is a link that I found: Determining age of a file in shell script 我正在尝试确定R中文件的年龄。这是我找到的一个链接: 在shell脚本中确定文件的年龄
I'm wondering is there any native R way to determine the age of a file in days unit(or hours). 我想知道是否有任何本地R方式来确定以天为单位(或小时)的文件的年龄。 Thank you for reading this.
谢谢您阅读此篇。
Update (I think this is working): 更新(我认为这是有效的):
ageoffile <- function(x,unit="sec"){
dt = .Internal(Sys.time())-.Internal(file.info(x))$mtime
if(unit=="hours")
return(dt/3600)
else if(unit=="days")
return(dt/(3600*24))
else return(dt)
}
You can get the information about your file using the file.info() function, and the current date and time using Sys.time() 您可以使用file.info()函数获取有关文件的信息,并使用Sys.time()获取当前日期和时间
info <- file.info("PATH_TO_YOUR_FILE")
Sys.time() - info$mtime
For instance: 例如:
> system("touch temp")
> info <- file.info("temp")
> Sys.time() - info$mtime
Time difference of 5.23292 secs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.