Delete old files with the same name as the generated output
This commit is contained in:
parent
df130c5d03
commit
2b377bbfca
18
Code.ts
18
Code.ts
@ -65,6 +65,12 @@ function spreadsheetRowToObject(
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trashFiles(files: GoogleAppsScript.Drive.FileIterator) {
|
||||||
|
while (files.hasNext()) {
|
||||||
|
files.next().setTrashed(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function generateForCurrentRow() {
|
function generateForCurrentRow() {
|
||||||
const spreadsheet = SpreadsheetApp.getActive();
|
const spreadsheet = SpreadsheetApp.getActive();
|
||||||
const cell = spreadsheet.getCurrentCell();
|
const cell = spreadsheet.getCurrentCell();
|
||||||
@ -82,10 +88,14 @@ function generateForCurrentRow() {
|
|||||||
'1ROyJXk-QANTHM6Jiw0ne3EQiR1f2UsLr'
|
'1ROyJXk-QANTHM6Jiw0ne3EQiR1f2UsLr'
|
||||||
);
|
);
|
||||||
|
|
||||||
const out_file = source_file.makeCopy(
|
const out_name = row['Document Name'] + '_' + row['Version'];
|
||||||
row['Document Name'] + row['Version'],
|
|
||||||
out_folder
|
// Delete old files with the same name
|
||||||
);
|
trashFiles(out_folder.getFilesByName(out_name));
|
||||||
|
trashFiles(out_folder.getFilesByName(out_name + '.pdf'));
|
||||||
|
|
||||||
|
// Duplicate source document and open
|
||||||
|
const out_file = source_file.makeCopy(out_name, out_folder);
|
||||||
const out_doc = DocumentApp.openById(out_file.getId());
|
const out_doc = DocumentApp.openById(out_file.getId());
|
||||||
|
|
||||||
// Copy header
|
// Copy header
|
||||||
|
Reference in New Issue
Block a user