fs::file_info() 中 modification_time 和 change_time 的区别
Difference between modification_time and change_time in fs::file_info()
R 包 fs provides the function file_info()
其中 returns 包含 i.a 的小标题。变量:
modification_time
最后一次数据修改的时间,作为 POSIXct 日期时间。
access_time
上次访问的时间 - 作为 POSIXct 日期时间。
change_time
上次文件状态更改的时间 - 作为 POSIXct 日期时间。
现在我想知道modification_time
和change_time
有什么区别?
到目前为止我注意到 change_time
似乎对 "chronological inconsistencies" 免疫。示例:
library(magrittr)
fs::file_create("test_file")
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:23:35 2019-10-24 13:23:35 2019-10-24 13:23:35
# change access and modification times to current Sys.time()
# -> both modification_time and change_time will be updated
Sys.sleep(1)
fs::file_touch("test_file")
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:23:37 2019-10-24 13:23:37 2019-10-24 13:23:37
# change access and modification times to the past (-2 min)
# -> only modification_time will be updated
fs::file_touch("test_file", Sys.time() - 120)
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:21:37 2019-10-24 13:21:37 2019-10-24 13:23:37
# change access and modification times to the future (+5 min)
# -> only modification_time will be updated
fs::file_touch("test_file", Sys.time() + 300)
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:28:37 2019-10-24 13:28:37 2019-10-24 13:23:37
由 reprex package (v0.3.0)
于 2019-10-24 创建
R 基函数 file.mtime()
仅 returns 来自上面的 modification_time
。
我想答案是双重的:
上面的例子具有误导性!当 access_time
或 modification_time
发生变化时,change_time
总是发生变化——只是从上面的输出中无法察觉,因为时间分辨率太低(秒)。
modification_time
给出文件修改时间戳。用户可以使用 touch
or the fs::file_touch()
函数等工具覆盖此(以及 access_time
)。
change_time
另一方面给出了元数据修改时间戳和不能直接由用户修改。元数据是指最后访问时间、最后修改时间、权限等属性listed in this answer to another Stack Overflow question.
R 包 fs provides the function file_info()
其中 returns 包含 i.a 的小标题。变量:
modification_time
最后一次数据修改的时间,作为 POSIXct 日期时间。access_time
上次访问的时间 - 作为 POSIXct 日期时间。change_time
上次文件状态更改的时间 - 作为 POSIXct 日期时间。
现在我想知道modification_time
和change_time
有什么区别?
到目前为止我注意到 change_time
似乎对 "chronological inconsistencies" 免疫。示例:
library(magrittr)
fs::file_create("test_file")
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:23:35 2019-10-24 13:23:35 2019-10-24 13:23:35
# change access and modification times to current Sys.time()
# -> both modification_time and change_time will be updated
Sys.sleep(1)
fs::file_touch("test_file")
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:23:37 2019-10-24 13:23:37 2019-10-24 13:23:37
# change access and modification times to the past (-2 min)
# -> only modification_time will be updated
fs::file_touch("test_file", Sys.time() - 120)
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:21:37 2019-10-24 13:21:37 2019-10-24 13:23:37
# change access and modification times to the future (+5 min)
# -> only modification_time will be updated
fs::file_touch("test_file", Sys.time() + 300)
fs::file_info("test_file") %>% dplyr::select(modification_time, access_time, change_time)
#> # A tibble: 1 x 3
#> modification_time access_time change_time
#> <dttm> <dttm> <dttm>
#> 1 2019-10-24 13:28:37 2019-10-24 13:28:37 2019-10-24 13:23:37
由 reprex package (v0.3.0)
于 2019-10-24 创建R 基函数 file.mtime()
仅 returns 来自上面的 modification_time
。
我想答案是双重的:
上面的例子具有误导性!当
access_time
或modification_time
发生变化时,change_time
总是发生变化——只是从上面的输出中无法察觉,因为时间分辨率太低(秒)。modification_time
给出文件修改时间戳。用户可以使用touch
or thefs::file_touch()
函数等工具覆盖此(以及access_time
)。change_time
另一方面给出了元数据修改时间戳和不能直接由用户修改。元数据是指最后访问时间、最后修改时间、权限等属性listed in this answer to another Stack Overflow question.