List all Google Drive links of Files / folder to Google Sheet

Google Drive is a powerful cloud storage service provided by Google which has a powerful tool called Google Apps Script and it is free. So, we can easily add, modify, delete files present in Google Drive. We can find docs, sheets, and slides by searching File Title, File Contents, etc. Using Google Drive for a while, you find useful of getting a list with URL of all those files and folder in Google Sheet so that you can track content of google drive.

We can easily create a list from Google Drive or export a Google Drive folder structure. So without wasting time let start.

Google Apps Script allows you to create a script that can add, modify and find files and folders present in google drives. We can list all Google Drive links of Files /Folders to Google Sheets with the help of these Google Apps Script.

Step 1 : Create new Google Sheets
Step 2 : In a sheet title bar ,select “Tools” >> “Script Editor”.
Step 3 : In the Script Editor, delete everything from the textbox and paste the following script.

function onOpen() {
  var SS = SpreadsheetApp.getActiveSpreadsheet();
  var ui = SpreadsheetApp.getUi();
    .addItem('List All Files and Folders', 'listFilesAndFolders')

function listFilesAndFolders(){
  var folderId = Browser.inputBox('Enter folder ID', Browser.Buttons.OK_CANCEL);
  if (folderId === "") {
    Browser.msgBox('Folder ID is invalid');
  getFolderTree(folderId, true); 

// Get Folder Tree
function getFolderTree(folderId, listAll) {
  try {
    // Get folder by id
    var parentFolder = DriveApp.getFolderById(folderId);
    // Initialise the sheet
    var file, data, sheet = SpreadsheetApp.getActiveSheet();
    sheet.appendRow(["Full Path", "Name","Type" ,"Date", "URL", "Last Updated", "Description", "Size (MB)", "Owner Email"]);
    // Get files and folders

    getChildFolders(parentFolder.getName(), parentFolder, data, sheet, listAll);
  } catch (e) {

// Get the list of files and folders and their metadata in recursive mode
function getChildFolders(parentName, parent, data, sheet, listAll) {
  var childFolders = parent.getFolders();
  // List folders inside the folder
  while (childFolders.hasNext()) {
    var childFolder =;
    var folderId = childFolder.getId();

    data = [ 
      parentName + "/" + childFolder.getName(),
    // Write
    // List files inside the folder
    var files = childFolder.getFiles();
    while (listAll & files.hasNext()) {
      var childFile =;
      data = [ 
        parentName + "/" + childFolder.getName() + "/" + childFile.getName(),

      // Write
    // Recursive call of the subfolder
    getChildFolders(parentName + "/" + childFolder.getName(), childFolder, data, sheet, listAll);  

Step 4 : Click on the Edit icon.
Step 5 : Goto the same Google Sheets File and refresh the page.
Step 6 : Then you will get the “List Files/Folders” menu, click on it, and select the “List All Files and Folders” item.
Step 7 : Popup will appear and there type folder Id.
Step 8 : Press the Ok button in the popup.
Then all your folders, files links are listed in google docs one by one. Depending on the number of files and folders of Google Drive, it may take some time to display all the files.

How to get FolderId?
To get folderId, first, go to the desired folder in google drive whose files/folders you want to list and then copy the random character just after ‘’ as shown below and then paste it in the above popup.

Leave a Reply


Your Cart

No products in the cart.
Start shopping

About Us

Royal Technologies is a System Integration house that supports Web Design, Web Hosting, Domain Registration, Search Engine Optimizing, IT Consulting, Remote or Telephone Support and Software Development. In simpler terms it’s an IT Company dealing in various aspects of implementation and maintenance of computerization. We have learnt from experience and have molded ourselves to be complete IT Company.



Copyright © 2008-2024 Royal Technologies. All rights reserved.
Development by Royal Technologies