Featured Post

Step Wise Project Planning

Planning is the most difficult process in project management. The framework described is called the Stepwise method to help to distinguis...

Google Apps Script that you can use to get the file names of all files in a Google Drive folder and write them to a Google Sheets spreadsheet



Google Apps Script that you can use to get the file names of all files in a Google Drive folder and write them to a Google Sheets spreadsheet


function getFileNames() {

  // Get the folder ID of the folder you want to list files from

  var folderId = "your_folder_id";

  

  // Get the folder using the ID

  var folder = DriveApp.getFolderById(folderId);

  

  // Get all the files in the folder

  var files = folder.getFiles();

  

  // Get the active sheet in the spreadsheet

  var sheet = SpreadsheetApp.getActiveSheet();

  

  // Write the header row in the sheet

  sheet.appendRow(["File Name"]);

  

  // Loop through all the files in the folder

  while (files.hasNext()) {

    var file = files.next();

    

    // Write the file name in the sheet

    sheet.appendRow([file.getName()]);

  }

}




You can run the script by clicking the "Run" button in the Google Apps Script editor. Make sure to replace "your_folder_id" with the actual ID of the folder you want to list files from.
Previous
Next Post »