Get file id dan file name dari file di google drive dan insert ke spreadsheet

video

app script

function listFilesInFolder() {
  var folderId = "xxx"; // ganti engan folder id anda
  var folder = DriveApp.getFolderById(folderId);
  var files = folder.getFiles();
  
  var spreadsheetId = "xxx"; // ganti dengan id spreadsheet anda
  var sheetName = "Sheet1"; //ganti dengan nama sheet yg dipilih
  var sheet = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName);
  
  var fileInfo = [];
  while (files.hasNext()) {
    var file = files.next();
    var fileId = file.getId();
    var fileName = file.getName();
    var fileUrl = getFileUrl(fileId);
    var fileDirectLink = getDirectLink(fileId);
    fileInfo.push([fileName, fileId, fileUrl, fileDirectLink]);
  }
  
  sheet.getRange(1, 1, fileInfo.length, 4).setValues(fileInfo);
}

function getFileUrl(fileId) {
  return "https://drive.google.com/file/d/" + fileId + "/view";
}

function getDirectLink(fileId) {
  return "https://drive.google.com/uc?id=" + fileId + "&export=download";
}