I have a folder containing around 4000 JPEG files. Among those 4000 files most of are corrupted and can not be opened by any photo viewer. The below screenshot is a corrupted JPEG file opened in windows photo viewer. enter image description here

Is it possible to delete those corrupted files using Mathematica "file operation"?

  • $\begingroup$ Can you link to one of those corrupted files? $\endgroup$ – dan7geo Oct 18 '16 at 16:57
  • $\begingroup$ @dan7geo find the hyperlink. $\endgroup$ – m. bubu Oct 18 '16 at 17:01
  • $\begingroup$ :/ A link to the screenshot of the corrupted file won't help. I need the actual file $\endgroup$ – dan7geo Oct 18 '16 at 17:23
  • $\begingroup$ @dan7geo check it now. $\endgroup$ – m. bubu Oct 18 '16 at 17:29

Run the following to get a list of files in your directory (replace the path with the path to your directory):

files = FileNames@"C:\\Users\\dan7g\\Desktop\\*.JPG"

Then run the following to delete the corrupt files:

DeleteFile@Select[files, $Failed == Import@# &]

Make sure you make a backup of the folder first, before doing this, in case something goes wrong.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.