javascript - How do I check if a file exists (by name) in Google Drive? -
using google apps script, i'm trying check if file exists in google drive, given name (nomedb
).
everywhere except in trash.
var habds = driveapp.getfilesbyname(nomedb); if(!habds.next()){ logger.log('it not exist'); }
now, driveapp.getfilesbyname
returns fileiterator, object. if object size zero, or doesn't exist, should solve problem, right?
instead of using .next(), use .hasnext() function. think run problems .next() trying grab file doesnt exist.
other code looks fine!
not 100% sure if .getfilesbyname() method returns empty fileiterator or null when no files found, if having issues test changing if statement conditions to
(!hasbds.hasnext() || habds == null)
Comments
Post a Comment