0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python3.7でバイナリ検索した結果をリストで出力する

Posted at

あー大変

工業標準化法の一部改正に伴い、2019/7/1から
法律名が「工業標準化法」から「産業標準化法」に改正されるそうです。

【JIS法改正(産業標準化法)(METI/経済産業省)】
https://www.meti.go.jp/policy/economy/hyojun/JISho.html

仕事で使っている帳票ツールの固定文字定義がバイナリ保管のようだったので、
文字コードで検索して、リストを出力する処理を作成しました。

環境設定

1.Python 3.7.2をインストールする。
2.python -m venv venv で仮想環境を作成する。

コード

出来るだけ、pip installしなくても良い内容で書いてみました。

import sys
import re
from pathlib import Path

p = Path("./")
pl = list(p.glob("**/*.*"))

outfile = open('SearchResult.txt', "w")

print("■■処理開始■■")

for plr in pl:
    print("  --" + Path.as_posix(plr))
    infile = open(plr, 'br')
    data = infile.read()
    infile.close()
    # 工業規格のSJIS文字コードで検索
    # Noneでない時(=対象文字が存在する場合)に出力
    if re.search(rb'\x8D\x48\x8B\xC6\x8B\x4B\x8A\x69',data) is not None:
        print("    @@" + Path.as_posix(plr))
        outfile.write(Path.as_posix(plr)+"\n")

outfile.close()
print("■■処理終了■■")

数か月後ですが、事前準備しておかないとバタつきますよね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?