我对这个平台还很陌生。
我试图制作一个Google Apps脚本来从我的Google文件夹中获取文件详细信息。我再次从Stack Overflow找到了脚本。
一切正常,直到现在运行出现错误为止。我无法诊断出同样的情况。
我现在已经创建了完全相同的文件的副本。
文件中有一个名为“脚本日志”的工作表,用于记录数据。
该脚本名为“驱动文件”。将在其中运行“ listAll”功能。
运行时,我会检查记录器并找到“异常:错误的值”
要提取的文件中的详细信息有些保密,这就是为什么我没有共享。
请帮助我更正代码。该文件位于此链接中。
https://docs.google.com/spreadsheets/d/1ktUe3qyf-TJp4K_FC8ELzLgh5q7jNRCP8YJF-z2li4A/edit?usp=sharing 下面是用于它的代码。
/**
* Google Apps Script - List all files & folders in a Google Drive folder,
& write into a speadsheet.
* - Main function 1: List all folders
* - Main function 2: List all files & folders
*
* Hint: Set your folder ID first! You may copy the folder ID from the
browser's address field.
* The folder ID is everything after the 'folders/' portion of the
URL.
*
* @version 1.0
* @see https://github.com/mesgarpour
*/
// TODO: Set folder ID
var folderId = '0B_BwvZZtlhP4OFNTeUhLX2NCWk0';
// Main function 1: List all folders, & write into the current sheet.
function listFolers(){
getFolderTree(folderId, false);
};
// Main function 2: List all files & folders, & write into the current
sheet.
function listAll(){
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.openById("d/1qP7AoydxJs7IkiURkLKkOzUSxTd1Ha8jLmETBq54zgI").getSheetByName("Script Logs")
sheet.clear();
sheet.appendRow(["Full Path", "Name", "Date", "URL", "Last Updated",
"Description", "Size"]);
// Get files and folders
getChildFolders(parentFolder.getName(), parentFolder, data, sheet,
listAll);
} catch (e) {
Logger.log(e.toString());
}
};
// 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 = childFolders.next();
// Logger.log("Folder Name: " + childFolder.getName());
data = [
parentName + "/" + childFolder.getName(),
childFolder.getName(),
childFolder.getDateCreated(),
childFolder.getUrl(),
childFolder.getLastUpdated(),
childFolder.getDescription(),
childFolder.getSize() / 1024,
];
// Write
sheet.appendRow(data);
// List files inside the folder
var files = childFolder.getFiles();
while (listAll & files.hasNext()) {
var childFile = files.next();
// Logger.log("File Name: " + childFile.getName());
data = [
parentName + "/" + childFolder.getName() + "/" + childFile.getName(),
childFile.getName(),
childFile.getDateCreated(),
childFile.getUrl(),
childFile.getLastUpdated(),
childFile.getDescription(),
childFile.getSize() / 1024,
];
// Write
sheet.appendRow(data);
}
// Recursive call of the subfolder
getChildFolders(parentName + "/" + childFolder.getName(), childFolder,
data, sheet, listAll);
}
};
谢谢。