ReminderVDP Posted July 6, 2022 Share Posted July 6, 2022 I've got a rule in a file that looks for a PDF on a server in a folder based on the file name. It's looking for the file based on a field in my data but I'm adding two zeros in the rule because the data field does not contain the zeros. For example, the data field has "9" in it. The file it is looking for has "009" in it. My current rule is this: var issueNumber = 'GH00' + Field("MagIDShort"); var pathName = "X:\\EDITORIAL\\FinalGutsforProofs\\GHM\\"; var FullResourcePath = pathName + issueNumber + "\\" + 'GH_magazine-00' + Field("MagIDShort") + ".pdf"; //change to match your data file field var x = new FusionProResource(FullResourcePath, "graphic", 1); if (!x.exists) ReportError("Graphic not found: " + FullResourcePath); var pdfString = ''; var pages = (x.countPages); for (var pgnbr = 1; pgnbr <= pages; pgnbr++) { x.pagenumber = pgnbr; pdfString += x.value + '<p>\n'; } Print("Result is: " + pdfString); return pdfString; It adds the two zeros in line 4. However, we are coming up on issue 10 so I will only need to add one zero to the rule, but I still have people making files looking for issue 9 and still need the two zeros in the file name. Is there some reg ex that would look for one or two zeros? I'm not good at reg ex so I'm looking for a solution that can be used for either file name, 009 or 010. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted July 6, 2022 Share Posted July 6, 2022 I think what you are looking for is the FormatNumber function FormatNumber("000", inputNumber) Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted July 6, 2022 Author Share Posted July 6, 2022 Thomas, Would that go in place of the 00 in the code below? + 'GH_magazine-00' Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted July 6, 2022 Share Posted July 6, 2022 Like this if I'm reading your code right: ... "\\" + 'GH_magazine-' + FormatNumber("000", Field("MagIDShort")) + ".pdf"; Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted July 7, 2022 Author Share Posted July 7, 2022 That's what I thought you meant. I will try that. Thanks! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted July 7, 2022 Share Posted July 7, 2022 If you want to test for multiple possibilities, you can do that in a loop, something like this: var x; for (var zeros = 0; zeros <= 3; zeros++) { var issueNumPadded = new Array((zeros || 0) + 1).join("0") + issueNumber; var FullResourcePath = pathName + issueNumber + "\\" + 'GH_magazine-' + issueNumPadded + ".pdf"; x = new FusionProResource(FullResourcePath, "graphic", 1); if (x.exists) break; } if (!x || !x.exists) ReportError("Graphic not found for " + issueNumber); Quote Link to comment Share on other sites More sharing options...
ReminderVDP Posted July 20, 2022 Author Share Posted July 20, 2022 Thanks Dan. I did get it to work with the code ThomasLewis put in here. That was a huge help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.