I'm trying to findout if a folder is actually a hard link to another, and in that case, findout its real path.
I did a simple example in python in the following way(symLink.py):
#python 3.4
import os
dirList = [x[0] for x in os.walk('.')]
print (dirList)
for d in dirList:
print (os.path.realpath(d), os.path.islink(d))
"""
Given this directories structure:
<dir_path>\Example\
<dir_path>\Example\symLinks.py
<dir_path>\Example\hardLinkToF2 #hard link pointing to <dir_path>\Example\FOLDER1\FOLDER2
<dir_path>\Example\softLinkToF2 #soft link pointing to <dir_path>\Example\FOLDER1\FOLDER2
<dir_path>\Example\FOLDER1
<dir_path>\Example\FOLDER1\FOLDER2
The output from executing: C:\Python34\python <dir_path>\Example\symLinks.py is:
['.', '.\\FOLDER1', '.\\FOLDER1\\FOLDER2', '.\\hardLinkToF2']
<dir_path>\Example False
<dir_path>\Example\FOLDER1 False
<dir_path>\Example\FOLDER1\FOLDER2 False
<dir_path>\Example\hardLinkToF2 False
"""
In this example os.path.islink always returns False both for a hard or a soft link. In the other hand, os.path.realpath returns the actual path for soft links, not for the hard links.
I've made this example using python 3.4 in Windows 8. I have no clue if I am doing something wrong or if there is another way to achieve it.