sebastian-c sebastian-c - 1 year ago 95
R Question

Check if two file paths resolve to the same file

Say I have three file paths:

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?

Answer Source

Use the full version of the filepaths and compare:

normalizePath(files[1]) == normalizePath(files[2])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download