#1 2006-06-15 08:13

LawOfNonContradiction
Member
From: USA
Registered: 2006-04-28
Posts: 45

Renamer: PascalScript: before or after dash

For filenames containing one dash I want to keep the longer portion ignoring the extension and make lowercase.

If  ReallyLong-short.avi then  ReallyLong.avi
If  this-thatotherthing.avi then thatotherthing.avi


From your example I created this kludge:

var
  BeforeDash, AfterDash: string;
  Marker: Integer;
begin
  Marker := Pos('-', FileName);
  if (Marker > 0) then
    begin
    BeforeDash := Copy(FileName, 1, Marker);
    AfterDash := Copy(FileName, Marker+1, Length(FileName));
    if (Length(AfterDash) > Length(BeforeDash)) then
      begin
          FileName := LowerCase(AfterDash);
      end;
    if (Length(BeforeDash) > Length(AfterDash)) then
      begin
          FileName := LowerCase(BeforeDash);
      end;
    end;
end.

Its not working as I expected.  It seems to be doing the opposite.  The TryToCompile button was helpful.  I left out a few begins and thens the first time through.

Offline

#2 2006-06-15 08:21

LawOfNonContradiction
Member
From: USA
Registered: 2006-04-28
Posts: 45

Re: Renamer: PascalScript: before or after dash

hmm.. if BeforeDash is longer this retains BeforeDash AND the dash itself.  I don't want the dash.

var
  BeforeDash, AfterDash: string;
  Marker: Integer;
begin
  Marker := Pos('-', FileName);
  if (Marker > 0) then
    begin
    BeforeDash := Copy(FileName, 1, Marker);
    AfterDash := Copy(FileName, Marker+1, Length(FileName));
    if (Length(AfterDash) > Length(BeforeDash)) then
      begin
          FileName := LowerCase(AfterDash) + LowerCase(ExtractFileExt(FileName));
      end;
    if (Length(BeforeDash) > Length(AfterDash)) then
      begin
          FileName := LowerCase(BeforeDash) + LowerCase(ExtractFileExt(FileName));
      end;
    end;
end.

sure I can use a remove rule, but for the purpose of this exercise I'd like to do it within PascalScript wink

Offline

#3 2006-06-15 10:32

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

Re: Renamer: PascalScript: before or after dash

Hi Law of NonContradiction,

Yes, you missed few little things.. For example, AfterDash will always contain the extension, and BeforeDash string will always contain the dash at the end. Anyway, here is the code that will do it the way you want it smile

var
  BeforeDash, AfterDash, Extension, BaseName: string;
  Marker: Integer;
begin
  BaseName := ExtractBaseName(FileName);
  Extension := ExtractFileExt(FileName);
  Marker := Pos('-', BaseName);
  if Marker > 0 then
    begin
    BeforeDash := Copy(BaseName, 1, Marker-1);
    AfterDash := Copy(BaseName, Marker+1, Length(BaseName));
    if Length(AfterDash) > Length(BeforeDash) then
      BaseName := LowerCase(AfterDash);
    if Length(BeforeDash) > Length(AfterDash) then
      BaseName := LowerCase(BeforeDash);
    FileName := BaseName + Extension;
    end;
end.

Offline

#4 2006-06-15 10:38

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

Re: Renamer: PascalScript: before or after dash

By the way, it's nice to see people playing with PascalScript rule smile

It can get very interesting, functionalities and possibilities of this rule - are unlimited!! big_smile

Offline

#5 2006-06-15 22:24

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renamer: PascalScript: before or after dash

You're not wrong smile

Last week a friend was here and during his stay he moaned about some files he had downloaded that were split into parts
I fired up delphi and talked him through what to do, trying to explain the reasons and getting him to understand it

Honest to god it was like christmas - seeing the look of delight on his face after writing his first program and having it work was wonderful

Offline

#6 2006-06-15 23:12

Qkid
Member
Registered: 2006-06-14
Posts: 20

Re: Renamer: PascalScript: before or after dash

Yeah Pascalscript is very good smile

If you need a program to manage mp3/audio files then try this:

The Godfather : http://users.otenet.gr/~jtcliper/tgf/

It has Pascalscript support and i've used it to write a script for outputing txt files etc with file info.

My TGF mirror is at: http://audiooctopus.planetmungo.co.uk/tgf/


Finally this site helped me a lot to revise the Pascal syntax, http://www.delphibasics.co.uk

Offline

#7 2006-06-15 23:33

dloneranger
Senior Member
From: Birmingham, UK
Registered: 2006-05-03
Posts: 122

Re: Renamer: PascalScript: before or after dash

If you can i'd recommend finding a personal edition of delphi to play with - pascalscript is very nice but a full version is nicer

I guess i'm lucky here, I get the top notch version to mess about with - I guess I should use it for database work, but there's always a few hours a day when I can squeeze in the things I want to do

Offline

#8 2006-06-16 14:45

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

Re: Renamer: PascalScript: before or after dash

Are you that lucky?.. Did you get BDS 2006 ? yikes

I'm still on Delphi 7, I like it, and my computer likes it as well tongue

Offline

#9 2006-07-17 13:12

LawOfNonContradiction
Member
From: USA
Registered: 2006-04-28
Posts: 45

Re: Renamer: PascalScript: before or after dash

ohhhh "ExtractBaseName"... that helps a bunch.  smile  thanks

Offline

Board footer

Powered by FluxBB