gpt4 book ai didi

javascript - 转换来自谷歌驱动器的所有 csvs

转载 作者:行者123 更新时间:2023-11-30 19:57:17 24 4
gpt4 key购买 nike

我正在尝试搜索我的谷歌驱动器中的所有 csvs,并将它们存储在具有电子表格格式的特定文件夹中。

我已经通过名称对特定的 csv 进行了相同的尝试,但现在我想要所有的 csv,但我不知道该怎么做。

function convert() {
var file = DriveApp.searchFiles("*filename*").next();
var name = file.getName();
var ID = file.getId();
var xBlob = file.getBlob();
var newFile = { title : name+'_converted',
key : ID,
parents: [{"id": "**folder id**"}]
}
file = Drive.Files.insert(newFile,xBlob, {convert: true});
}

最佳答案

如果您上面列出的代码已经可以一次检索单个 CSV 文件,您需要做的就是将其包装在一个循环中,该循环将继续运行文件,直到所有文件都被处理。它应该看起来像这样:

// You will need to use the syntax in Google's developer guide to search with searchFiles:
// https://developers.google.com/apps-script/reference/drive/drive-app#searchfilesparams

// This should find any files with the text '.csv'. If there are false positives, you can change this to 'mimeType contains "csv"' to look for files with either application/csv or text/csv mime types
var files = DriveApp.searchFiles('title contains ".csv"');
// The code inside the while statement will run on each file until there are no more files in the array from searchFiles
while (files.hasNext()) {
// Gets the next file in the array of files
var file = files.next();
var name = file.getName();
var ID = file.getId();
var xBlob = file.getBlob();
var newFile = { title : name+'_converted',
key : ID,
parents: [{"id": "**folder id**"}]
}
file = Drive.Files.insert(newFile,xBlob, {convert: true});
}

这是否回答了您的问题?

关于javascript - 转换来自谷歌驱动器的所有 csvs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53833243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com