List Files and Links from a Google Drive Folder in Google Sheets
This Apps Script example writes the name and URL of each file in a Drive folder to the active Google Sheet. Use a folder you are authorised to access and avoid publishing a sheet that contains confidential file names.
function listDriveFiles() {
const folderId = 'YOUR_FOLDER_ID';
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const files = DriveApp.getFolderById(folderId).getFiles();
const rows = [['File name', 'URL']];
while (files.hasNext()) {
const file = files.next();
rows.push([file.getName(), file.getUrl()]);
}
sheet.clearContents();
sheet.getRange(1, 1, rows.length, rows[0].length).setValues(rows);
}Run it
- Open the destination Sheet and choose Extensions > Apps Script.
- Paste the function and replace
YOUR_FOLDER_IDwith the ID from the Drive folder URL. - Run the function and approve the requested Google permissions for your account.
- Confirm the rows match the files you expect.
This lists files directly inside the selected folder. Recursively walking subfolders requires additional logic and should include safeguards for large folder trees.