更新时间:2022-05-11 01:42:24
我相信您的目标如下.
1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
文件夹中的所有文件. 1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
文件夹下的文件夹中检索了文件. 1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
的文件夹中有2个文件夹,而2个文件夹中有1个文件和1个文件夹,其中每个文件夹中有1个文件,则脚本将检索2个文件.因为脚本从 1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
文件夹下的文件夹中检索文件.1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
are retrieved.
1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
has 2 folders and the 2 folders has 1 file and 1 folder including 1 file in each folder, your script retrieves 2 files. Because the script retrieves the files from the folders just under the folder of 1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e
.当以上几点反映到脚本中时,它如下所示.
When above points are reflected to the script, it becomes as follows.
function DeleteInvoices() {
const getAllFiles = folder => {
const files = folder.getFiles();
while (files.hasNext()) {
const file = files.next();
console.log(file.getName());
file.setTrashed(true);
}
const folders = folder.getFolders();
while (folders.hasNext()) getAllFiles(folders.next());
}
var folder = DriveApp.getFolderById("1-2VAPBzEQxCaoN7KGSB_K_peiLIDk32e");
getAllFiles(folder);
}
getAllFiles
功能扫描所有子文件夹中的所有文件,并删除这些文件.(它们已移至垃圾箱.)
getAllFiles
, and the files are removed. (They are moved to the trash box.)