我在Google云端硬盘上有包含数百张图片的文件夹。我想通过文件名的文件夹及其共享链接来生成电子表格,这样我就可以创建CSV文件以在其他位置进行批量链接。
我可以批量复制可共享链接,而不是使用代码,而是通过选择Google云端硬盘中的所有文件,右键单击并使用共享功能。这将生成可复制并粘贴到电子表格的链接列表。但是,我无法将它们与文件名匹配。
我已经找到了一个脚本(如下),用于导出名称和直接链接(而不是共享链接)的列表,但是无法获得导出顺序的匹配。
用于列出文件名和直接链接的脚本如下:
// replace your-folder below with the folder for which you want a listing
function listFolderContents() {
var foldername = 'your-folder';
var folderlisting = 'listing of folder ' + foldername;
var folders = DriveApp.getFoldersByName(foldername)
var folder = folders.next();
var contents = folder.getFiles();
var ss = SpreadsheetApp.create(folderlisting);
var sheet = ss.getActiveSheet();
sheet.appendRow( ['name', 'link'] );
var file;
var name;
var link;
var row;
while(contents.hasNext()) {
file = contents.next();
name = file.getName();
link = file.getUrl();
sheet.appendRow( [name, link] );
}
};
答案 0 :(得分:0)
// replace your-folder below with the folder for which you want a listing
function listFolderContents() {
var foldername = 'your-folder';
var folderlisting = 'listing of folder ' + foldername;
var folders = DriveApp.getFoldersByName(foldername)
var folder = folders.next();
var contents = folder.getFiles();
var ss = SpreadsheetApp.create(folderlisting);
var sheet = ss.getActiveSheet();
sheet.appendRow(['name', 'link']);
var file;
var name;
var link;
var row;
while (contents.hasNext()) {
file = contents.next();
name = file.getName();
link = "https://drive.google.com/uc?export=download&id=" + file.getId();
sheet.appendRow([name, link]);
}
};