簡體   English   中英

確定R中文件的年齡

[英]Determining age of a file in R

我正在嘗試確定R中文件的年齡。這是我找到的一個鏈接: 在shell腳本中確定文件的年齡

我想知道是否有任何本地R方式來確定以天為單位(或小時)的文件的年齡。 謝謝您閱讀此篇。

更新(我認為這是有效的):

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)
}

您可以使用file.info()函數獲取有關文件的信息,並使用Sys.time()獲取當前日期和時間

info <- file.info("PATH_TO_YOUR_FILE")
Sys.time() - info$mtime

例如:

> 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM