Is there any less time consuming way to check if file's Root Directory is "My Drive" or "Team Drive"?
I have tried using file.getParents();
and then iterating through every parent and finally to Root, but this is way too time consuming.
When a file is in Team Drive, the owner is the Team Drive and not any particular user.
You can perform a check for ownership on the file and if it is set to null, the file is likely inside Team Drive.
var file = DriveApp.getFileById("fileID");
if (file.getOwner() === null) {
// do something here
}