I know a folder actually is a file with a special mimeType application/vnd.google-apps.folder
in Google Drive.
But documentation about DriveApp Folder class doesn't contain a method getMimeType() like DriveApp File class does.
How can find out in a function if an argument of that function refers to a folder or to a (normal) file?
function displayResults(fileOrFolder)
{
var id = fileOrFolder.getId();
var name = fileOrFolder.getName();
var mimeType = fileOrFolder.getMimeType(); // works if file; error if folder
if (fileOrFolder == <Class File>)
{
<do something>
}
else if (fileOrFolder == <Class Folder>)
{
<do something else>
}
}
Get the file object associated to the ID. getMimeType() will work:
Look if the method exists. If obj.getMimeType===undefined its a folder.
or, to make it more robust in case the api changes (adds the method to folders), use
if (obj.getMimeType===undefined || obj.getMimeType.toLowerCase() =="application/vnd.google-apps.folder")
I don't understand why you say that Zig's answer does not work... All the tests I made were positive.
example of how I tested it (test ID are shared publicly and so should work for anybody):