Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Fixes MSSQL scripts encoding in UTC-2 (UTF-16) to be UTF-8.
- """
- import os
- SCRIPTS_DIR = os.path.expanduser("~/Projects/scripts")
- def read_file(file, encoding='utf-16'):
- if not os.path.exists(file):
- raise Exception("File does not exist: {}".format(file))
- with open(file, 'r', encoding=encoding) as fh:
- return fh.read()
- def write_file(file, contents, encoding='utf-8'):
- with open(file, 'w', encoding=encoding) as fh:
- return fh.write(contents)
- def main():
- sql_files = []
- for root, dirs, files in os.walk(SCRIPTS_DIR):
- for file in [f for f in files if f.endswith(".sql")]:
- sql_files.append(os.path.join(root, file))
- for file in sql_files:
- contents = read_file(file, encoding='utf-16')
- write_file(file, contents, encoding='utf-8')
- print(file)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement