• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env python3
2
3"Replace LF with CRLF in argument files.  Print names of changed files."
4
5import sys, re, os
6
7def main():
8    for filename in sys.argv[1:]:
9        if os.path.isdir(filename):
10            print(filename, "Directory!")
11            continue
12        with open(filename, "rb") as f:
13            data = f.read()
14        if b'\0' in data:
15            print(filename, "Binary!")
16            continue
17        newdata = re.sub(b"\r?\n", b"\r\n", data)
18        if newdata != data:
19            print(filename)
20            with open(filename, "wb") as f:
21                f.write(newdata)
22
23if __name__ == '__main__':
24    main()
25