Export a file without the unique ID file name

Post Reply
pcarvalho
Newbie
Posts: 16
Joined: Tue Dec 16, 2014 12:08 pm

Export a file without the unique ID file name

Post by pcarvalho »

I have a script that export a indd file to rtf, xml and PDF.

The resulted files have the unique ID file name (_001OL_Teste_DOC1.rtf).
How can i generate a file without that unique ID?

Heres a portion of the script:

var name = $filename;
//========== Export to RTF ===========
myRTFFile = new File($arg3 + "/" +name+".rtf" );
try{
var myStory = $doc.textFrames.itemByName("a_textframe").parentStory;
myStory.exportFile (ExportFormat.rtf, myRTFFile);
}
catch(theError) {
$doc.close(SaveOptions.DONOTSAVECHANGES);
$error = theError.description;
}
...
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Export a file without the unique ID file name

Post by dkelly »

Code: Select all

var name = $filename.right($filename.length-7);
pcarvalho
Newbie
Posts: 16
Joined: Tue Dec 16, 2014 12:08 pm

Re: Export a file without the unique ID file name

Post by pcarvalho »

thanks dkelly, but JavaScript does not offer Left and Right functions.

Works with
var name = $filename.substring(7, $filename.length);
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Export a file without the unique ID file name

Post by dkelly »

Switch does
left( length : Number ) : String
Returns a substring containing the length leftmost characters of this string.
right( length : Number ) : String
Returns a substring containing the length rightmost characters of this string.
and for Adobe apps you can define as

Code: Select all

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
Last edited by dkelly on Tue May 26, 2015 6:21 pm, edited 1 time in total.
loicaigon
Member
Posts: 147
Joined: Wed Jul 10, 2013 10:22 am

Re: Export a file without the unique ID file name

Post by loicaigon »

pcarvalho wrote:JavaScript does not offer Left and Right functions.
You have to distinguish the core language know as Javascript and its different implementations with different object models and extended functions. Also even a basic object like a RegExp object has different methods from where you use it. You won't find Right() in other implementation such as ExtendScript. Most of all, you have to keep aware that inspite a very minimalistic set of primitive objects and function, Javascript can differ widely from one context to another.

FWIW,

Loic
Post Reply