Nov-22-2017, 03:09 PM
I agree with @DeaD_EyE in that the "Magic" number will probably get you the most 'positive' results. Some things to remember though, the Magic number is not a fixed length. Some may be 3 bytes, others 8, for example. Some files have no Magic number, a good example is the "Plain Text" file (think Windows Notepad). Our beloved Python files (.py) have no Magic number, as they are, after all, plain text files. You could get some positive results if you tested for "#! /", but of course that is only if the author included the shebang line as the first line of the file.
That depends on if you are looking for one specific file type, a group of similar file types or all file types. For a specific type, you could just assign the number to a variable, for a group, you would probably want a dictionary, for all types you would probably be best served with a database.
Quote:... Finally, how do i check the value and find its type and print it out, please?
That depends on if you are looking for one specific file type, a group of similar file types or all file types. For a specific type, you could just assign the number to a variable, for a group, you would probably want a dictionary, for all types you would probably be best served with a database.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition