Advertisement
METAJIJI

list max deep dirs

Mar 20th, 2015
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import os
  5.  
  6. s = set()
  7. for path, dirs, files in os.walk('/tmp/1'):
  8.     if path:
  9.         s.add(path)
  10.  
  11.  
  12. def path_max(p):
  13.     return len(p.split(os.sep))
  14.  
  15.  
  16. maxlen = len(max(s, key=path_max).split(os.sep))
  17. for i in s:
  18.     if len(i.split(os.sep)) == maxlen:
  19.         print i
  20.  
  21. # $ tree /tmp/1
  22. # /tmp/1
  23. # └── 2
  24. #    └── 3
  25. #        └── 4
  26. #            ├── 5
  27. #            ├── a
  28. #            ├── b
  29. #            └── c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement