Guest User

Untitled

a guest
Jun 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import os
  2.  
  3. def convert_line_endings(file, lineEndFrom='\r\n', lineEndTo='\n'):
  4. with open(file, 'rb') as f:
  5. content = f.read()
  6. content = content.replace(lineEndFrom.encode(), lineEndTo.encode())
  7.  
  8. with open(file, 'wb') as f:
  9. f.write(content)
  10. print("Converted:", file)
  11.  
  12. def get_all_files(path, extensions=()):
  13. alljsfiles = []
  14. for (dirpath, directory_names, file_names) in os.walk(path):
  15. if extensions == ():
  16. jsfiles = [os.path.join(dirpath, f) for f in file_names]
  17. else:
  18. jsfiles = [os.path.join(dirpath, f) for f in file_names if f.endswith(extensions)]
  19. alljsfiles += jsfiles
  20. return alljsfiles
  21.  
  22. def convert_all_line_endings_of_js_files(path):
  23. files = get_all_files(path, ('.js','.jsx'))
  24. for file in files:
  25. convert_line_endings(file)
  26.  
  27. convert_all_line_endings_of_js_files('demo')
Add Comment
Please, Sign In to add comment