Retrieving File ID from File Name using GAS

This is a sample script of GAS for converting file name to file id on Google Drive. Drive API is used for this. So please enable Drive API at Advanced Drive Services and Google API Console.

function nameToId(filename){
  return [i.id for each (i in Drive.Files.list({q: "title='" + filename + "' and trashed=false"}).items)];
}

 Share!