Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. #
  4. # Copyright (c) 2008 Doug Hellmann All rights reserved.
  5. #
  6. """This script creates the example directory and its contents.
  7. """
  8.  
  9. __version__ = "$Id$"
  10. #end_pymotw_header
  11.  
  12. import os
  13.  
  14. def mkfile(filename, body=None):
  15. with open(filename, 'w') as f:
  16. f.write(body or filename)
  17. return
  18.  
  19. def make_example_dir(top):
  20. if not os.path.exists(top):
  21. os.mkdir(top)
  22. curdir = os.getcwd()
  23. os.chdir(top)
  24.  
  25. os.mkdir('dir1')
  26. os.mkdir('dir2')
  27.  
  28. mkfile('dir1/file_only_in_dir1')
  29. mkfile('dir2/file_only_in_dir2')
  30.  
  31. os.mkdir('dir1/dir_only_in_dir1')
  32. os.mkdir('dir2/dir_only_in_dir2')
  33.  
  34. os.mkdir('dir1/common_dir')
  35. os.mkdir('dir2/common_dir')
  36.  
  37. mkfile('dir1/common_file', 'this file is the same')
  38. mkfile('dir2/common_file', 'this file is the same')
  39.  
  40. mkfile('dir1/not_the_same')
  41. mkfile('dir2/not_the_same')
  42.  
  43. mkfile('dir1/file_in_dir1', 'This is a file in dir1')
  44. os.mkdir('dir2/file_in_dir1')
  45.  
  46. os.chdir(curdir)
  47. return
  48.  
  49. if __name__ == '__main__':
  50. os.chdir(os.path.dirname(__file__) or os.getcwd())
  51. make_example_dir('example')
  52. make_example_dir('example/dir1/common_dir')
  53. make_example_dir('example/dir2/common_dir')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement