Difference between revisions of "ReNamer:Scripts:EAN-13"
Jump to navigation
Jump to search
(Created page with '{{Up|ReNamer:Scripts}} This script will calculate the checksum digit for the [http://en.wikipedia.org/wiki/EAN-13 EAN-13 barcode]. The checksum digit will be appended to the end…') |
(added another example) |
||
Line 18: | Line 18: | ||
| 002010000003.png | | 002010000003.png | ||
| 002010000003<span style="color: red">8</span>.png | | 002010000003<span style="color: red">8</span>.png | ||
+ | |- | ||
+ | | 007567816412.png | ||
+ | | 007567816412<span style="color: red">5</span>.png | ||
|} | |} | ||
Revision as of 18:39, 9 June 2010
This script will calculate the checksum digit for the EAN-13 barcode. The checksum digit will be appended to the end of the base name.
Input | Output |
---|---|
002010000000.png | 0020100000007.png |
002010000001.png | 0020100000014.png |
002010000002.png | 0020100000021.png |
002010000003.png | 0020100000038.png |
007567816412.png | 0075678164125.png |
Tested
- ReNamer 5.50+ Beta
Code
Author: Denis Kozlov. Date: 9 June 2010.
function EAN13Checksum(const EAN13: String): Integer;
var
I, Digit: Integer;
Odd: Boolean;
Sum: Integer;
begin
Sum := 0;
Odd := True;
for I := Length(EAN13) downto 1 do
begin
Digit := StrToIntDef(EAN13[I], 0);
if Odd then
Sum := Sum + Digit * 3
else
Sum := Sum + Digit;
Odd := not Odd;
end;
Result := Sum mod 10;
if Result <> 0 then
Result := 10 - Result;
end;
var
BaseName, Ext: WideString;
Checksum: Integer;
begin
BaseName := WideExtractBaseName(FileName);
Ext := WideExtractFileExt(FileName);
Checksum := EAN13Checksum(BaseName);
FileName := BaseName + IntToStr(Checksum) + Ext;
end.