Last active
December 27, 2015 06:59
-
-
Save hoffoo/7285657 to your computer and use it in GitHub Desktop.
check for corrupt image files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image" | |
_ "image/gif" | |
_ "image/jpeg" | |
_ "image/png" | |
"os" | |
"fmt" | |
) | |
func main() { | |
cwd, _ := os.Getwd() | |
cwdd, err := os.Open(cwd) | |
if err != nil { | |
panic(err) | |
} | |
files, _ := cwdd.Readdir(-1) | |
for _, f := range files { | |
file, err := os.Open(cwd + "/" + f.Name()) | |
if err != nil { | |
println("failed opening " + f.Name()) | |
continue | |
} | |
_, _, err = image.Decode(file) | |
if err != nil { | |
fmt.Println(f.Name(), " seems corrupt: ", err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment