Python Sample Identify File Type
Jump to navigation
Jump to search
This sample shows how to determine the type of a file using Python.
File Type and Details
This sample will print the file type of the file as well as the details in JSON format. This script is available on GitHub.
import sys
import mmap
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
def main() -> None:
with open(sys.argv[1], mode="r") as input_file:
with mmap.mmap(input_file.fileno(), length=0, access=mmap.ACCESS_READ) as memory_buffer:
b = memory_buffer.read()
file_type = truxton.identify(b)
print( "File Type is " + str(file_type) )
details = truxton.details(file_type, b)
print( details )
return None
if __name__ == "__main__":
sys.exit(main())