I need to stop os.walk from going down further if the path contains both "release" and "arm-linux". I have a bunch of these at different levels of directories. So I can't simply dictate the level. So far I have the following and it unnecessarily dive past directories in 'arm-linux'.
def main(argv):
for root, dirs, files in os.walk("."):
path = root.split(os.sep)
if "release" and "arm-linux" in path:
print(os.path.abspath(root))
getSharedLib(argv)
[update] This is my solution
def main(argv):
for root, dirs, files in os.walk("."):
path = root.split(os.sep)
if "release" in path and "arm-linux" in path:
print(os.path.abspath(root))
getSharedLib(argv)
del dirs[:]
From the documentation
Note that topdown is True by default.
Edit
To delete all the elements of
dirs, you will need something likedel dirs[:]. That will delete all the elements of the list object that is referred to asdirsin your code, but is referred to by another name in theos.walkcode.Just using
del dirswill stopdirsin your code from referring to the list, but won't do anything to theos.walkreference. Similarlydirs = []will replace whatdirsin your code refers to, but won't affectos.walkcode.