我正在尝试打印google驱动器中父文件夹中的所有文件夹名。
我尝试了这么多方法,但没有起作用。
const drive = google.drive({ version: 'v3', auth });
console.log("Drive => ", drive.drives.appdata);
drive.files.list({
//spaces: 'drive',
//isRoot: true,
//pageSize: 10,
}, (err, res) => {
console.log(err);
if (err) return console.log('The API returned an error: ' + err);
const files = res.data.files;
if (files.length) {
console.log('Files:');
files.map((file) => {
console.log(file);
});
} else {
console.log('No files found.');
}
});
上面的代码只给出了这些文件夹的文件名,但是我试图打印所有父文件夹名。?
我需要打印angular_files, datastructurealgo,DSA,Tools
的名字。这些都是文件夹。
发布于 2021-02-25 16:17:01
您可以使用来自正式文件的代码搜索Google中的文件夹。这里的关键是使用q: "mimeType='application/vnd.google-apps.folder'"
作为drive.files.list
的参数。
示例代码:
const drive = google.drive({ version: 'v3', auth });
console.log("Drive => ", drive.drives.appdata);
drive.files.list({
q: "mimeType='application/vnd.google-apps.folder'",
fields: 'nextPageToken, files(id, name)',
spaces: 'drive',
pageToken: pageToken
}, (err, res) => {
console.log(err);
if (err) return console.log('The API returned an error: ' + err);
if (res.files.length) {
res.files.forEach(function (folder) {
console.log('Found folder: ', folder.name, folder.id);
});
pageToken = res.nextPageToken;
} else {
console.log('No folders found.');
}
});
请注意,您可能需要根据您的需要调整代码。
https://stackoverflow.com/questions/66370396
复制相似问题