CHKim

check file encoding

Sep 25th, 2016
242
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from tkinter import *
  2. import chardet
  3. import os
  4. import wave
  5. import sys
  6.  
  7. rootDir = './'
  8. fileExt = '.py'
  9. fileCount = 0
  10.  
  11. def traversal():
  12.     global rootDir
  13.     global fileCount
  14.  
  15.     for dirName, subdirList, fileList in os.walk(rootDir):
  16.     #   print('Found directory: %s' % dirName)
  17.         for fname in fileList:
  18.             if fname.endswith(fileExt):
  19.                 f = open(rootDir + fname, 'rb')
  20.                 buf = f.read()
  21.                 f.close()
  22.  
  23.                 r = chardet.detect(buf)
  24.                 encoding = r['encoding'].lower()
  25.                 if encoding.find('utf-8') == -1:
  26.                     print("%s \t: %s" % (fname, encoding))
  27.                     fileCount = fileCount + 1
  28.                 del r
  29.  
  30. traversal()
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment