Copy link to clipboard
Copied
Hi,
I'm trying to check the document name and ask the user to rename it if it doesn't conform to this format xxxxxx Issxx.
I'm having trouble renaming the file. I understand you have to close the document before you can rename it.
Can anyone offer any advice for me code?
var doc = app.activeDocument;
function renameMe () {
var p = prompt( "Please enter a valid file name" );
checkInput(p);
var file = doc.filePath,
myFileName = doc.name.substr( 0, doc.name.indexOf( "." ) ),
myNewFileName = myFileName.replace( myFileName, p + ".indd" );
doc.close();
//need to close the doc and find the folder to rename
var newFile = file.rename( myNewFileName );
app.open( file );
}
function checkInput (check) {
if ( !check.match( "\\d{6}\\sIss\\d+" ) ) {
alert( "File name should follow convention 000000 Iss0" );
renameMe();
}
}
if (!doc.name.match( "\\d{6}\\sIss\\d+" ) ) {
renameMe();
}
Thanks,
Jake
Hi,
Replace theline:
var file = doc.filePath, // which in fact is a file parent (folder)
with
var file = doc.fullName,
Jarek
Copy link to clipboard
Copied
Hi,
Replace theline:
var file = doc.filePath, // which in fact is a file parent (folder)
with
var file = doc.fullName,
Jarek
Copy link to clipboard
Copied
Perfect! You gave me the last piece of the puzzle