Created
August 1, 2018 15:18
-
-
Save Monal5031/85b94de036369e0676e8e5b1646cef6d to your computer and use it in GitHub Desktop.
Python script to convert windows line ending CRLF to Unix LF.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
directory_in_str = os.path.dirname(os.path.realpath(__file__)) | |
windows_line_ending = b'\r\n' | |
linux_line_ending = b'\n' | |
all_files = [] | |
for root, dirs, files in os.walk(directory_in_str): | |
for name in files: | |
if name.endswith('.py'): | |
full_path = os.path.join(root, name) | |
if full_path.find('migrations') == -1: | |
all_files.append(full_path) | |
for filename in all_files: | |
print(filename) | |
with open(filename, 'rb') as f: | |
content = f.read() | |
content = content.replace(windows_line_ending, linux_line_ending) | |
with open(filename, 'wb') as f: | |
f.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Consider closing the opened files.