#1 2006-09-06 15:54

tsekos
Member
Registered: 2006-09-06
Posts: 2

Help with the pascal script

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

#2 2006-09-07 10:22

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Help with the pascal script

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

#3 2006-09-07 10:39

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Help with the pascal script

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

#4 2006-09-09 06:39

tsekos
Member
Registered: 2006-09-06
Posts: 2

Re: Help with the pascal script

thnx.

i will try this.

nice work with the program.

Offline

Board footer

Powered by FluxBB