I have a drive folder with a few g-sheet files (each larger than 100MB).
I want to override the content of the oldest file with the content of the newest file.
And then trash all files but the oldest one.
I have two problems:
1) Exception in file "Code".
2) My content can be larger than 10MB.
Is it a dead end?
function deleteOldSheets() {
var df = DriveApp.getFolderById("1haqAtxk7ZeXF9ayEbRFIf7yGi3KBu4S_");
var arr = new Array();
var files = df.getFiles();
while( files.hasNext() ) {
var f = files.next();
arr.push( [ [ f.getId() ] , [ f.getLastUpdated() ] ] );
}
if (arr.length < 2){
return;
}
arr.sort( sortFunction );
var mediaData = DriveApp.getFileById(arr[0][0]).getBlob().getDataAsString();
DriveApp.getFileById(arr[arr.length-1][0]).setContent(mediaData);
for( var i=0 ; i<arr.length-1 ; i++ ){
DriveApp.getFileById( arr[i][0] ).setTrashed( true );
}
};
function sortFunction( a , b ) {
var aDate = new Date(a[1]);
var bDate = new Date(b[1]);
if ( aDate === bDate ) return 0;
else if ( aDate < bDate ) return 1;
else return -1;
};
[![enter image description here][1]][1]