Python os.walk + follow symlinks

Set followlinks to True. This is the fourth argument to the os.walk method, reproduced below:

os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])

This option was added in Python 2.6.

EDIT 1

Be careful when using followlinks=True. According to the documentation:

Note: Be aware that setting followlinks to True can lead to
infinite recursion if a link points to a parent directory of itself.
walk() does not keep track of the directories it visited already.

Leave a Comment