Look at the data flow:
You call listfiles()
with a path. It collects all files below that path in a list.
(BTW, IMHO dir = dirName.replace(path, '')
is dangerous. What happens if path
is lib/
and you encouter a sub path lib/misc/collected/lib/whatever
? While this path males not much sense, it might have been created...)
You return this list from listfiles()
and then convert them into sets.
If you try to iterate over these sets, you get one path per iteration step.