Dandigit/sloc

Check if file is plain text

plastictortoise opened this issue · 3 comments

@Dandigit

If I use all in a directory that contains png files, It comes up with an error message
"Traceback (most recent call last):
File "sloc.py", line 58, in
totalLines = getTotalLines(getFlags())
File "sloc.py", line 54, in getTotalLines
totalLines += countLinesInFile(os.path.join(root, file))
File "sloc.py", line 38, in countLinesInFile
for i, l in enumerate(file):
File "C:\Users\bpassaportis\AppData\Local\Programs\Python\Python37-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 144: character maps to "
.
I know you could probably us python-magic to work out whether any given file is plain text. Example Here.
I know I could specify all the file types that I want to, but this could be a problem for someone who has hundreds of different types of files in a directory.

  • SimpleBinary

I will try and do this, I just made this in case i cannot.

@simplebinary For a little script like this, dependencies are undesirable. I can think of a couple of ways to fix this without using python-magic.

Fixed in #3.