You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
623 B

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