Skip to content

Instantly share code, notes, and snippets.

@l3robot
Created July 30, 2014 15:22
Show Gist options
  • Select an option

  • Save l3robot/3985e40fb8e941f90c5c to your computer and use it in GitHub Desktop.

Select an option

Save l3robot/3985e40fb8e941f90c5c to your computer and use it in GitHub Desktop.
Python script to find false .jpg files in a directory. It finds PNG files -- python 3.3
import os
a = input("Enter the directory name here : ");
b = os.listdir(a)
for i in b:
c = a + i
f = open(c, "rb")
image = f.read()
if image[0] == 0x89 and image[1] == 0x50:
print("Will transform " + i + " in PNG, because it's a PNG file...")
name = i[0:-4] + ".png"
command = "mv " + a + i + " " + a + name
os.system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment