Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def convert_line_endings(file, lineEndFrom='\r\n', lineEndTo='\n'):
- with open(file, 'rb') as f:
- content = f.read()
- content = content.replace(lineEndFrom.encode(), lineEndTo.encode())
- with open(file, 'wb') as f:
- f.write(content)
- print("Converted:", file)
- def get_all_files(path, extensions=()):
- alljsfiles = []
- for (dirpath, directory_names, file_names) in os.walk(path):
- if extensions == ():
- jsfiles = [os.path.join(dirpath, f) for f in file_names]
- else:
- jsfiles = [os.path.join(dirpath, f) for f in file_names if f.endswith(extensions)]
- alljsfiles += jsfiles
- return alljsfiles
- def convert_all_line_endings_of_js_files(path):
- files = get_all_files(path, ('.js','.jsx'))
- for file in files:
- convert_line_endings(file)
- convert_all_line_endings_of_js_files('demo')
Add Comment
Please, Sign In to add comment