With GScripts you can use the following functions to create/modify the files:
This one creates a new Spreadsheet with all Folder names and all corresponding URLS (no header)
function mapAllFiles() {
var values = [];
var folders = DriveApp.getFoldersByName("FOLDER_NAME");
while (folders.hasNext()) {
var folder = folders.next();
var files = folder.getFiles();
// Looping over all files in all folders with the given name
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
var fileInfo = [file.getName(), file.getDownloadUrl()];
Logger.log(fileInfo);
values.push(fileInfo);
// values.push(file.getDownloadUrl());
}
}
// To use an exiting spreadsheet
// var sFile = DriveApp.getFilesByName("YOUR_SPREADSHEET_NAME");
// var as = SpreadsheetApp.openById(sFile.next().getId());
// Create a new spreadsheet
var as = SpreadsheetApp.create("YOUR_SPREADSHEET_NAME");
var sheet = as.getActiveSheet();
// Fill in all values
var range = sheet.getRange(1, 1, values.length, 2).setValues(values);
}
This one list the URLs for the given fileNames in the spreadsheet which are present in the folder
function mapListedFiles() {
var values = [];
var folders = DriveApp.getFoldersByName("FOLDER_NAME");
if (folders.hasNext()) {
var folder = folders.next();
var sFile = DriveApp.getFilesByName("YOUR_SPREADSHEET_NAME");
var as = SpreadsheetApp.openById(sFile.next().getId());
// var as = SpreadsheetApp.create("YOUR_SPREADSHEET_NAME");
var sheet = as.getActiveSheet();
var range = sheet.getRange(2,1,sheet.getDataRange().getLastRow(), 1).getValues();
for (var i = 0; i < range.length-1; i++) {
var files = folder.getFilesByName(range[i]);
Logger.log(files);
if (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
Logger.log(file.getDownloadUrl());
values.push([file.getDownloadUrl()]);
} else {
values.push(["MISSING"]);
}
}
var range = sheet.getRange(2, 2, values.length, 1).setValues(values);
}
}