Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pathlib
- import glob
- def check(pattern):
- signatures = {
- 'jpg': bytes([255, 216, 255]),
- 'png': bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]),
- }
- read_size = max(len(sig) for sig in signatures.values())
- for file in glob.glob(pattern):
- file = pathlib.Path(file)
- if not file.is_file():
- continue
- with file.open('rb') as fd:
- data = fd.read(read_size)
- for extension, signature in signatures.items():
- if data.startswith(signature):
- print('{} is a {} file.'.format(file, extension))
- check('Downloads/*')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement