Check if two file paths resolve to the same file

筅森魡賤 提交于 2019-12-24 01:53:53

问题


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:


Use the full version of the filepaths and compare:

normalizePath(files[1]) == normalizePath(files[2])


来源:https://stackoverflow.com/questions/39095537/check-if-two-file-paths-resolve-to-the-same-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!