# charset="CP932" # encode="CP932" # JPEG EOF Checker # # は再帰的でないので。 # Mac OS 8.1 以前の File name に 31 bytes しか使えない環境で Rename する場合は # 1 文字だけ追加する様にするか、最後の文字を入れ替えるとより安全でせう。 #!/usr/bin/env perl require 5.002; use strict; use subs qw{ report($$$) jec($) rd($) dorj($) }; $::s = $^O =~ /MacOS/ ? ':' : $^O =~ /DOS|Win32|OS2/i ? '\\' : '/'; sub report($$$) { my ($h, $i, $f) = @_; $h and $i and return; warn "$f: "; unless ($h) { rename $f, "$f.soi-error" or die; warn "... SOI "; } unless ($i) { $h and rename $f, "$f.eoi_error" or die; warn "... EOI "; } warn "error.\n"; } sub jec($) { my ($h, $i); open F, $_[0] or die; seek F, 1, 0; read F, $h, 1; seek F, -1, 2; read F, $i, 1; close F; report $h eq "\xD8", $i eq "\xD9", $_[0]; } sub rd($) { opendir DIR, $_[0] or die; for (grep !/^\./, readdir DIR) { dorj(join $::s, $_[0], $_); } closedir DIR; } sub dorj($) { -d $_[0] ? rd $_[0] : jec $_[0]; } warn "---> Start JFIF EOF Check...\n"; dorj $::v while defined($::v = shift @ARGV); warn "---> Done JFIF EOF Check.\n"; __END__ #!/usr/bin/env python import os import string import sys def report(s, r, jfif): if s and r: return None else: print jfif, if not s: os.rename(jfif, jfif + '.soi-error') print '... SOI ', if not r: if s: os.rename(jfif, jfif + '.eoi_error') print '... EOI ', print 'error' def jec(jfif): if not string.lower(jfif[-4:]) in ('.jpg', 'jpeg', 'pjpg'): return None f = open(jfif) f.seek(1, 0) s = f.read(1) f.seek(-1, 2) r = f.read(1) f.close() report(s == 'xD8', r == 'xD9', jfif) def ls(s, d, e): for p in e: dsp = d + s + p if os.path.isfile(dsp): jec(dsp) if __name__ == '__main__': for i in sys.argv[1:]: if os.path.isdir(i): os.path.walk(i, ls, os.sep) elif os.path.isfile(i): jec(i) sys.exit() (* AppleScript *) property |SUI| : ASCII character 216 property |EOI| : ASCII character 217 property |TYP| : {"JPEG", "JFIF"} property |EXT| : {"jpg", "jfif", "jpeg", "jpe", "pjpeg", "pjpg"} on alr(|I|, |O|) tell application "Finder" set label index of |I| to |O| if |O| is not 0 then reveal |I| end tell end alr on jec(|I|) set |O| to 0 open for access |I| returning F read F for 1 from 2 if result is not |SUI| then set |O| to 1 + |O| read F for 1 from -1 if result is not |EOI| then set |O| to 2 + |O| close access F alr(|I|, |O|) end jec on each(i) info for i if result's folder is true then list folder i repeat with x in result (i as text) & (x as text) each(alias result) end repeat else if result's file type is in |TYP| or result's name extension is in |EXT| then jec(i) end if end each on open argv repeat with i in argv each(i) end repeat end open on run tell application "Finder" repeat with i in {} & selection my each(i as alias) end repeat end tell end run