I currently have a google spreadsheet that will create a csv file and save it on my google drive when the trigger goes off. What I can't figure out is how to delete the existing csv file before creating a new csv file. When it saves the new version, it simply makes another copy. I need to overwrite the previous file (or delete the old one then export/write the new version.)
Here is the script to create the csv file:
function saveAsCSV() {
// Prompts the user for the file name
var fileName = ("myCSVFile");
// Check that the file name entered wasn't empty
if (fileName.length !== 0) {
// Add the ".csv" extension to the file name
fileName = fileName + ".csv";
// Convert the range data to CSV format
var csvFile = convertRangeToCsvFile_(fileName);
// Create a file in the Docs List with the given name and the CSV data
DriveApp.createFile(fileName, csvFile);
}
else {
Browser.msgBox("Error: Please enter a CSV file name.");
}
}
How can I overwrite the csv file every time the script trigger goes off?