My script takes 35 student names from the Sheet \'Studenti\'. Then finds the proper folder with their name (i.e. \'Smith Peter\'), removes old pdf document with old grades h
In the SO post, the user is trying to delete the converted file and got the same error as you are.
I suspect you're hitting a rate limit. If you are doing more than 20 write operations (create, update, delete) in rapid succession, you need to throttle the requests to approximately one every 1.5 seconds.
Suspected reason is the user hits rate limit. Since you are also updating a data, there is also a possibility that this is the reason why it is working on the first few execution and reached the limit after.
And that is the only allotted maximum throughput you can achieve in Drive.
After few experiments I found the roots of the problem but not the solution. The problem with "Access denied" was related to the fact, that I was not the owner of the file created by my script and only the owner of the file may trash or delete the file. Although I was author of the script and had edit rights to the file which was placed on my drive, it did not work. On the other hand I could delete/trash the file manually without problems (and it was misleading for me).
Lesson learnt: If you allow someone else to use your script that creates a new file and also trashes the old one than you probably cannot complete your script next time sice you are not allowed (Access denied) to trash the file created by other user (although the file was created on your own drive !).
Adjusted question: Does anybody know how to write the script to trash/delete the file of which I am not the owner ( but I have edit rights) and which was created by other user on my drive?
I have the same problem with trashing files, that I don't own. I found that
I didn't find a way to remove unwanted files from my drive in case 2 and 3 thru apps script. But it's still possible by clicking on them and choosing option "Remove".