Given these folders
s:\test\zoneA\UnitA
s:\test\zoneB\UnitA
s:\test\zoneB\UnitB\Item_1
I would like to pass to a 开发者_如何学JAVAfunction 's:\test' and get unique bottom list of folders
Resulting in what you see above... 3 entries. Instead, when I use my function
import os
for top, dirs, files in os.walk('S:\\\test'):
for nm in dirs:
print os.path.join(top, nm)
I get...
S:\test\zoneA
S:\test\zoneB
S:\test\zoneA\UnitA
S:\test\zoneB\UnitA
S:\test\zoneB\UnitB
S:\test\zoneB\UnitB\Item_1
Is there a way to get the bottom folder list ? Thanks much.
I guess what you want are folders without subfolders?
import os
for path, dirs, files in os.walk('S:\\\test'):
if not dirs:
print path
精彩评论