You are not logged in.
Pages: 1
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
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
Offline
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
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
By the way, it's nice to see people playing with PascalScript rule
It can get very interesting, functionalities and possibilities of this rule - are unlimited!!
Offline
You're not wrong
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
Yeah Pascalscript is very good
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
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
Are you that lucky?.. Did you get BDS 2006 ?
I'm still on Delphi 7, I like it, and my computer likes it as well
Offline
ohhhh "ExtractBaseName"... that helps a bunch. thanks
Offline
Pages: 1