-2

I have a file with .dir extension. I tried opening it but getting unknown/unreadable characters. I also tried opening it using python and java but not able to get the correct encoding/decoding for the characters in file. Can someone help me in this or provide some other application in which I can open this file? I have tried the below code in python but getting unreadable characters:

with open(file_name, "rb") as binary_file:
    data = binary_file.read()
    dec_str = data.decode('utf-8', errors='ignore')
    print(dec_str)
Red
  • 26,798
  • 7
  • 36
  • 58
Mal
  • 1

1 Answers1

1

You can use the lovely chardet package to infer file encoding.

import chardet

with open(file_name, "rb") as binary_file:
    data = binary_file.read()
    enc = chardet.detect(data)
    dec_str = data.decode(enc['encoding'], errors='ignore')
    print(dec_str)

See official docs for details.

b0lle
  • 732
  • 6
  • 19