Created
April 3, 2014 14:00
-
-
Save pwm1234/9954932 to your computer and use it in GitHub Desktop.
find windows links (aka junctions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import win32file | |
import win32con | |
def islink(p): | |
# return os.path.islink(p) | |
fattr = win32file.GetFileAttributes(p) | |
isWinJunction = fattr & win32con.FILE_ATTRIBUTE_REPARSE_POINT | |
if isWinJunction > 0: | |
return True | |
else: | |
return False | |
def findlink(dirsOnly, dirname, names): | |
# print >> sys.stderr, 'findlink({0}, {1}, {2})'.format(dirsOnly, dirname, names) | |
for n in names: | |
p = os.path.join(dirname, n) | |
if dirsOnly: | |
if os.path.isdir(p) and islink(p): | |
print >> sys.stdout, 'link: {0}'.format(p) | |
else: # not dirsOnly | |
if islink(p): | |
print >> sys.stdout, 'link: {0}'.format(p) | |
else: | |
# print >> sys.stdout, 'nolk: {0}'.format(p) | |
pass | |
def findlinks(dirname, dirsOnly): | |
print >> sys.stderr, "finding links in {0}".format(dirname) | |
os.path.walk(dirname, findlink, dirsOnly) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print >> sys.stderr, 'usage: python findlinks.py dir' | |
sys.exit(-1) | |
dir = sys.argv[1] | |
findlinks(dir, dirsOnly=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment