Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env
- # -*- coding: utf-8 -*-
- # based on dir_mapper by Ivan.G
- # http://pastebin.com/ccE0FpPu
- import os
- def dir_mapper(start_directory, target_file, indent = 0):
- dirlist = [direcotry for direcotry in os.listdir(start_directory)]
- filelist = [filename for filename in dirlist if not os.path.isdir(os.path.join(start_directory, filename))]
- dirlist = [directory for directory in dirlist if os.path.isdir(os.path.join(start_directory, directory))]
- if len(filelist) == 0:
- pass
- for f in filelist:
- target_file.write((' ' * indent)+ '--' + f.encode('utf-8')+'\n')
- if len(dirlist) == 0:
- pass
- for d in dirlist:
- target_file.write((' ' * indent)+ d.encode('utf-8')+'\n')
- new_indent = indent + 4
- dir_mapper(os.path.join(start_directory, d), target_file, new_indent)
- if __name__ == "__main__":
- f = open('list.txt', 'w')
- dir_mapper(u"D:\\Аспирантура\\", f)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment