You are not logged in.
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
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
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
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!
Last edited by TCARPENTER67 (2009-03-04 16:47)
Offline
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!
Offline
Nuts!
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.
Any suggestions?
Offline
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
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
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!
Offline