home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Dos / rmcr.py < prev    next >
Encoding:
Python Source  |  1995-12-17  |  504 b   |  29 lines  |  [TEXT/R*ch]

  1. #! /usr/local/bin/python
  2.  
  3. import sys
  4. import os
  5.  
  6. def main():
  7.     args = sys.argv[1:]
  8.     if not args:
  9.         print 'no files'
  10.         sys.exit(1)
  11.     for file in args:
  12.         print file, '...'
  13.         changed = 0
  14.         lines = open(file, 'r').readlines()
  15.         for i in range(len(lines)):
  16.             line = lines[i]
  17.             if line[-2:] == '\r\n':
  18.                 lines[i] = line[:-2] + '\n'
  19.                 changed = 1
  20.         if changed:
  21.             print 'rewriting...'
  22.             os.rename(file, file + '~')
  23.             open(file, 'w').writelines(lines)
  24.             print 'done.'
  25.         else:
  26.             print 'no change.'
  27.  
  28. main()
  29.