Rename book with the name of the first chapter.
var myFolder = Folder.selectDialog( "Selecione a pasta dos arquivos para criação do Book." );
if ( myFolder != null ) {
var myFiles = [];
GetSubFolders(myFolder);
if ( myFiles.length > 0 ) {
var myBookFileName = myFolder + "/"+ myFolder.name + ".indb";
myBookFile = new File( myBookFileName );
if ( myBookFile.exists ) {
if ( app.books.item(myFolder.displayName + ".indb") == null ) {
myBook = app.open( myBookFile );
}
}
else {
myBook = app.books.add( myBookFile );
myBook.automaticPagination = false;
myBook.synchronizeBulletNumberingList = false
myBook.synchronizeCellStyle= false
myBook.synchronizeCharacterStyle= false
myBook.synchronizeConditionalText= false
myBook.synchronizeCrossReferenceFormat= false
myBook.synchronizeMasterPage= false
myBook.synchronizeObjectStyle= false
myBook.synchronizeParagraphStyle= false
myBook.synchronizeSwatch= false
myBook.synchronizeTableOfContentStyle= false
myBook.synchronizeTableStyle= false
myBook.synchronizeTextVariable= false
myBook.synchronizeTrapStyle= false
for ( i=0; i < myFiles.length; i++ ) {
myBook.bookContents.add( myFiles );
}
myBook.save();
}
}
}
//=================================== FUNCTIONS =========================================
function GetSubFolders(theFolder) {
var myFileList = theFolder.getFiles();
for (var i = 0; i < myFileList.length; i++) {
var myFile = myFileList;
if (myFile instanceof Folder){
GetSubFolders(myFile);
}
else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
myFiles.push(myFile);
}
}
}
I have this code to create book based on the folder where the file is, but how would you rename the book by the name of the first chapter of the book? Thank you for your help.
