Kestable

dir_mapper_by_Ivan.G

Feb 24th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3.  
  4. def dir_mapper(start_directory, target_file, indent = 0):
  5.     dirlist = [direcotry for direcotry in os.listdir(start_directory)]
  6.     dirlist = [directory for directory in dirlist if os.path.isdir(os.path.join(start_directory, directory))]
  7.                
  8.     if len(dirlist) == 0:
  9.         pass
  10.     for d in dirlist:
  11.         target_file.write((' ' * indent)+ d.encode('utf-8')+'\n')
  12.         new_indent = indent + 4
  13.         dir_mapper(os.path.join(start_directory, d), target_file, new_indent)
  14.  
  15.  
  16. if __name__ == "__main__":
  17.     f = open('list.txt', 'w')
  18.     dirlist = dir_mapper("E:\\music\\", f)
  19.     f.close()
Advertisement
Add Comment
Please, Sign In to add comment