Guido van Rossum | 09eea82 | 1998-09-14 15:46:41 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 09eea82 | 1998-09-14 15:46:41 +0000 | [diff] [blame] | 2 | "Replace CRLF with LF in argument files. Print names of changed files." |
| 3 | |
Guido van Rossum | affa6b7 | 2002-11-13 21:04:31 +0000 | [diff] [blame] | 4 | import sys, os |
Andrew M. Kuchling | e236b38 | 2004-08-09 17:27:55 +0000 | [diff] [blame^] | 5 | |
| 6 | def main(): |
| 7 | for filename in sys.argv[1:]: |
| 8 | if os.path.isdir(filename): |
| 9 | print filename, "Directory!" |
| 10 | continue |
| 11 | data = open(filename, "rb").read() |
| 12 | if '\0' in data: |
| 13 | print filename, "Binary!" |
| 14 | continue |
| 15 | newdata = data.replace("\r\n", "\n") |
| 16 | if newdata != data: |
| 17 | print filename |
| 18 | f = open(filename, "wb") |
| 19 | f.write(newdata) |
| 20 | f.close() |
| 21 | |
| 22 | if __name__ == '__main__': |
| 23 | main() |
| 24 | |