function deleteFiles(fileId,supportsTeamDrives) { var date = new Date(); date.setDate(date.getDate() - 180); var n = date.toISOString().split('.')[0] ; var test = false; gapi.client.drive.files.list({ pageSize: x, q: "starred = "+test+" and viewedByMeTime < '"+n+"'", orderBy: 'quotaBytesUsed desc', fields: "nextPageToken, files(id, name, viewedByMeTime, mimeType, quotaBytesUsed)", } ) .then(function(response) { var files = response.result.files; if (files && files.length > 0) { for (var i = 0; i < files.length; i++) { var file = files[i]; var file_id = file.id, )'); }} var request = gapi.client.drive.files.delete({ supportsTeamDrives: 'false', fileId: file_id , }); } request.execute(function(resp) { }); }

I want this function to list out the fileIDs, as as each fileID is put out, they get deleted. How do I combine list file and delete file functions together for this to work?

Currently I separated them into two functions, but the variable fileID only saves the last fileID outputted, thus, the delete function would only delete one file, the last file listed. I want it to list and output every file to a varable and as its listed it gets deleted. What can I change or add in my goal to accomplish this?