Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os
- def dir_mapper(start_directory, target_file, indent = 0):
- dirlist = [direcotry for direcotry in os.listdir(start_directory)]
- dirlist = [directory for directory in dirlist if os.path.isdir(os.path.join(start_directory, directory))]
- 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')
- dirlist = dir_mapper("E:\\music\\", f)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment