Skip navigation
greenrookie
Currently Being Moderated

change filename using GREP

Jul 5, 2012 12:36 PM

Hello,

 

I'm trying to get these lines of code to change the filename when saving;

 

from: zAlcatraz

to: HAlcatraz

 

if(myDocName.indexOf("z")!=-1){

var myRegularExpression = /\\<z/gi

myDocName = myDocName.replace(myRegularExpression, "H");

}

 

I'm trying to target just the first z at the front of every filename but can't get the grep correct.

 

Any thoughts?

 

Thanks in advance,

 

GR

 
Replies
  • Currently Being Moderated
    Jul 5, 2012 9:23 PM   in reply to greenrookie

    Hi,

        Use the below codes...

     

    myDocument = app.activeDocument;

    path = myDocument.fullName;

    var x = path.toString().replace("z", "H");

    myDocument.save(File(x));

     

    Hope this will help you...

     

    Thanks and Regards,

    Vel.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 6, 2012 1:25 AM   in reply to greenrookie

    Vel's code will replace all instances of lowercase 'z' with uppercase 'H' -- even the ones in the file path.

     

    Better try this:

     

    myDocName = app.activeDocument.fullName.path+'/'+app.activeDocument.fullName.name .replace(/^z/i, "H");

     

    (The GREP code you were probably looking for is '^' -- start of 'line', in this case equal to the start of the string.)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points