#1 2009-03-03 20:28

TCARPENTER67
Member
Registered: 2009-03-03
Posts: 5

Increment the length and width by 1 - Pascal Question?

This is probably a rookie question but here goes:

I have a list of files which contain length and width information in them.  I need to increment the length and width by 1.  I'm guessing this is a quick and dirty pascal script but I've never done Pascal so I'm not sure how to use the ReplaceRegEx and MatchesRegEx functions.  If somebody can point me in the right direction, I'd appreciate it.  Even if there's an easy way I've overlooked in some of the canned stuff in ReNamer.   My filenames look like this:
ExQRLeft_Starburst0x2x6x1-XYDriving.ipt, I need to change the "6x1" to "7x2". 

Great program by the way - thanks for that!:)

Offline

#2 2009-03-04 07:23

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Increment the length and width by 1 - Pascal Question?

I don't suppose you want the 0x2 in that example touched? If so, try this piece of PascalScript code and let me know if it works for all cases:

var
  arr: TStringsArray;

begin
  arr := SubMatchesRegEx(FileName, '(.*)x(\d+)x(\d+)-(.*)', False);
  FileName := arr[0] + 'x' + IntToStr(StrToInt(arr[1])+1) + 'x' + IntToStr(StrToInt(arr[2])+1) + '-' + arr[3];
end.

Offline

#3 2009-03-04 15:40

TCARPENTER67
Member
Registered: 2009-03-03
Posts: 5

Re: Increment the length and width by 1 - Pascal Question?

Hi Andrew,

It did work - sort of...  I keep getting an error saying:

 

Warning, found 128 invalid filename(s)!
  128 of which config with existing filepath(s).

 

Complied succesfully!
  (Line 0) Hint:  Variable 'FILEPATH' never used

I'm not sure what that means, but the renaming routine is bombing out.  I tried just to keep hitting the rename button, the results of which were not pretty.

Thanks for the help.  Any other suggestions?

Offline

#4 2009-03-04 16:44

TCARPENTER67
Member
Registered: 2009-03-03
Posts: 5

Re: Increment the length and width by 1 - Pascal Question?

Okay - just because I'm a hack - and absolutely no Pascal experience, (I'm just VBA guy), I threw in the FilePath var:

var
  arr: TStringsArray;

begin
  arr := SubMatchesRegEx(FileName, '(.*)x(\d+)x(\d+)-(.*)', False);
  FileName := FilePath + arr[0] + 'x' + IntToStr(StrToInt(arr[1])+1) + 'x' + IntToStr(StrToInt(arr[2])+1) + '-' + arr[3];
end.

And it worked great!  Thanks again Andrew for getting me going!  big_smile

Last edited by TCARPENTER67 (2009-03-04 16:47)

Offline

#5 2009-03-04 16:57

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Increment the length and width by 1 - Pascal Question?

Ah, possibly the directory information (path) was required as you were dragging and dropping files from different directories... I tested with sample files in the same dir as ReNamer.exe, so it worked.

Anyway, glad you got it to work! smile

Offline

#6 2009-03-04 17:09

TCARPENTER67
Member
Registered: 2009-03-03
Posts: 5

Re: Increment the length and width by 1 - Pascal Question?

Nuts! hmm

I spoke too soon.  The compiler was happy, and the grid below had green arrow next to them.  When I told it to rename, nothing happened - even though ReNamer came back successful.  When I looked closer at the grid showing the old name and new name, this is what I saw:

ExQRLeft_Starburst0x1x2x3-XYDriving.2dm  -->   C:\Grids-JP\EXQRLeft_EQC01\ExQRLeft_Starburst0x1x2x3-XYDriving.2dmExQRLeft_Starburst0x1x3x4-XYDriving.2dm

So I tried using the FilePath without the FileName - nothing.  I cleary don't get how Pascal works.  Now I'm at a complete loss.  sad

Any suggestions?

Offline

#7 2009-03-04 17:27

prologician
Member
Registered: 2009-01-30
Posts: 84

Re: Increment the length and width by 1 - Pascal Question?

Well, you don't ~need~ FILEPATH in scripts to have a happy, compiling program. That's just a variable that Denis puts in there in order for you to be able to adjust the path, if you need it. (So far, I myself haven't used it, but it's kinda nice to know it's there.)

One thing I did come across, though, is that names could be called "conflicting" if the output name of one file collides with the input name of another file. As in... let's say you have files 7x1.2dm and 8x2.2dm. You expect them both to have the numbers incremented, as you describe. However, notice that 7x1 actually ~becomes~ 8x2 by this process. Therefore, it's labeled as a collision, and thus ReNamer squawks.

Instead of doing all your renames at once, break it up into several batches. That should avoid this kind of headache.

Offline

#8 2009-03-04 19:02

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Increment the length and width by 1 - Pascal Question?

I'm not sure if I am right, but sorting filenames in filetable in descending order might help.
Then you should get 8x2 incremented to 9x3 BEFORE 7x1 become 8x2.
I have no time to test it so it's just a guess.

Last edited by krtek (2009-03-04 19:03)


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#9 2009-03-04 21:51

TCARPENTER67
Member
Registered: 2009-03-03
Posts: 5

Re: Increment the length and width by 1 - Pascal Question?

prologician and krtek,

prologician, you explained and krtek, your technique made Andrew's code work as is.  Just FYI, ReNamer squawks a warning when it validates the names, but it renames the file just the way it should.

Thanks for taking the time guys! big_smile

Offline

Board footer

Powered by FluxBB