Advertisement
gleechinese

no_exotic.py

Sep 25th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # Python script for removing EXOTIC tags in Dwarf Fortress RAW files
  3. #
  4. # Chee Sing Lee <cheesinglee@gmail.com>
  5. # 25 September 2011
  6.  
  7.  
  8. from os import walk
  9. from os import getcwd
  10. from os.path import join
  11. from fnmatch import fnmatch
  12. from shutil import copy2
  13. import io
  14.  
  15. # recursively walk the directory tree, starting from current directory
  16. for (dirpath,dirnames,fnames) in walk( getcwd() ):
  17.     for fname in fnames:
  18.         if fnmatch(fname,'creature_*.txt'):
  19.             filepath = join(dirpath,fname)
  20.             # make a backup first
  21.             copy2(filepath,filepath+'.bak')
  22.            
  23.             # read the file
  24.             f = io.FileIO(filepath,'r+')
  25.             f_string = f.read()
  26.             f_string = f_string.replace('[PET_EXOTIC]','[PET]')
  27.             f_string = f_string.replace('[MOUNT_EXOTIC]','[MOUNT]')
  28.             # rewind so that we are overwriting
  29.             f.seek(0)    
  30.             f.write(f_string)
  31.             f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement