You are not logged in.
Pages: 1
I need to mass rename photos.
Their current naming format is
(4digit width) x (4digit height) name number
example: 0800 x 0600 Elizabeth Hurley 1230.jpg
I need help with writing a scipt that calculates the heigth/width ratio and puts it in the name
example: (0600/0800) * 1000 = 750 (No need for demicals)
new name: 0750 0800 x 0600 Elizabeth Hurley 1230.jpg
Mostly I need the functions that
1) will read the numbers (0600, 0800) from the name
2) make them integers
p.s. If anyone feels like writing the hole code, shouldn't feel like I won't like it.
Thanks in advance for any kind of help.
Offline
There was a discussion on a similar topic: Question about changing numbers in file names.
That's only for your information, but I'll post the full code later today...
Offline
The code below will change "0800 x 0600 Elizabeth Hurley 1230.jpg" to "0750 0800 x 0600 Elizabeth Hurley 1230.jpg"
var
TrimedName: WideString;
NumInt1, NumInt2, Ratio: Integer;
NumStr1, NumStr2: string;
function RemoveSpaces(const Text: WideString): WideString;
var I: Integer;
begin
Result := '';
for I:=1 to WideLength(Text) do
if not IsWideCharSpace(WideGetChar(Text, I)) then
Result := Result + WideGetChar(Text, I);
end;
function PadLeft(Number, NewLength: Integer): string;
begin
Result := IntToStr(Number);
while Length(Result) < NewLength do
Result := '0' + Result;
end;
begin
TrimedName := RemoveSpaces(FileName);
NumStr1 := WideCopy(TrimedName, 1, 4);
NumStr2 := WideCopy(TrimedName, 6, 4);
NumInt1 := StrToIntDef(NumStr1, -1);
NumInt2 := StrToIntDef(NumStr2, -1);
if (NumInt1 > 0) and (NumInt2 > 0) then
begin
Ratio := Round((NumInt2 / NumInt1) * 1000);
FileName := PadLeft(Ratio, 4) + ' ' + FileName;
end;
end.
Offline
thnx.
i will try this.
nice work with the program.
Offline
Pages: 1