This Google Apps Script new script shows a dialog with :
- a label with the text: “Enter the file name to search for:” ;
- an edit box for the name of the file;
- the Ok button to run the script;
The script will search the file ID and will show you a dialog message like this:
File ID: your_File_ID_of the file
This is the source code I used:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu("File ID Search") .addItem("Find File ID", "findFileID") .addToUi(); } function findFileID() { var ui = SpreadsheetApp.getUi(); var fileName = ui.prompt("Enter the file name to search for:").getResponseText(); var fileId = getFileIdByName(fileName); if (fileId) { ui.alert("File ID: " + fileId); } else { ui.alert("File not found."); } } function getFileIdByName(fileName) { var files = DriveApp.getFilesByName(fileName); if (files.hasNext()) { var file = files.next(); return file.getId(); } else { return null; } } |