def is_subdir(path, directory):
    path = os.path.realpath(path)
directory = os.path.realpath(directory)
relative = os.path.relpath(path, directory)
How to check whether a directory is a sub directory of another directory