I have list from os.walk
. But I want to exclude some directories and files. I know how to do it with directories:
for root, dirs, files in os.wa
All above answers are working. Just wanted to add for anyone else whos files by any chance are coming from heterogeneous sources, e.g. downloading images in archives from the Internet. In this case, because Unix-like systems are case sensitive you may end up having extension like '.PNG' and '.png'. These will be treated by as different strings by endswith
method, i.e. '.PNG'.endswith('png')
will return False
. In order to avoid this problem, use lower()
function.