Skip to content

Instantly share code, notes, and snippets.

@sh16ma
Last active November 6, 2022 06:38
Show Gist options
  • Save sh16ma/c0d137fa37121a6f859588bea6ba2d30 to your computer and use it in GitHub Desktop.
Save sh16ma/c0d137fa37121a6f859588bea6ba2d30 to your computer and use it in GitHub Desktop.
#🐍 #Python #Eecel #Encoding
# DLした「.csv」ファイルを一括文字コード変換
# cf. https://dse-souken.com/2021/06/06/tec/
# HowToUse
# 1. DLしたファイルをまとめてフォルダー化して「enc」と名付ける
# 2.「enc」フォルダー内にあるDLしたファイルを全てデスクトップへコピペ
# 3.「jis_encoding.py」を実行
import glob
from pathlib import Path
path_u = Path('./Desktop')
path_s = Path('./Desktop/enc') #DLファイルをまとめて「enc」という名のディレクトリ作成してコピペ
ufiles = list(path_u.glob('*.csv'))
sfiles = list(path_s.glob('*.csv'))
files_dict = dict(zip(ufiles, sfiles))
#デスクトップ内CSVファイルの中身を、「enc」ディレクトリ内の同名ファイルに書き込み変換
for ufile, sfile in files_dict.items():
with open(ufile, encoding='utf-8', error='replace') as f:
with open(sfile, 'w', encoding='cp932', error='replace') as encod: #cp932=Shift-JISに書換
encod.write(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment