Check if two file paths resolve to the same file

2019-07-12 18:43发布

Say I have three file paths:

setwd("C:/superlongdirname")
files <- c("C:/superlongdirname/myfile.txt", "C:\\SUPERL~1\\myfile.txt", "./myfile.txt")

These all point to the same file. How, given multiple references to the same file, can I check that they are indeed referring to the same file within R?

1条回答
Root(大扎)
2楼-- · 2019-07-12 19:26

Use the full version of the filepaths and compare:

normalizePath(files[1]) == normalizePath(files[2])
查看更多
登录 后发表回答