Jump to content

Reg Ex or Javascript for File Name

Recommended Posts

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.

Link to comment
Share on other sites

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)
if (!x || !x.exists)
   ReportError("Graphic not found for " + issueNumber);

Link to comment
Share on other sites

  • 2 weeks later...

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...