我有这个,我运行了调试程序,它没有给我任何错误。在哪里可以搜索带有某些单词的文件?任何帮助将不胜感激。
这是我正在尝试使用的
var filesIterator = folder.searchFiles('title contains "Untitled"');
function MoveFiles() {
var SourceFolder = DriveApp.getFolderById('abcdefghijklmnopqrstuvwxyz');
var SourceFiles = DriveApp.getFolderById('abcdefghijklmnopqrstuvwxyz').getFiles();
var DestFolder = DriveApp.getFolderById('1hbuV93CsdOeHkZWLES8BhXYMrayoKTBr');
while (SourceFiles.hasNext()) {
var file = SourceFiles.next();
DestFolder.addFile(file);
SourceFolder.removeFile(file);
}
}
答案 0 :(得分:0)
此功能将显示一个提示,您可以在其中输入字符串以完成查询“标题包含“字符串””。您还必须提供要搜索的文件夹的 id 和目标文件夹的 id 。
function findAndMoveFiles() {
var SourceFolder = DriveApp.getFolderById('Id');
var DestFolder = DriveApp.getFolderById('Id');
var result = SpreadsheetApp.getUi().prompt('Enter the string to complete the search query');
var qry = Utilities.formatString('title contains "%s"', result.getResponseText());//you just need to enter the string that gets put into %s
var SourceFiles = SourceFolder.searchFiles(qry);
while (SourceFiles.hasNext()) {
var file = SourceFiles.next();
DestFolder.addFile(file);
SourceFolder.removeFile(file);
}
}
在脚本编辑器的gs文件中输入脚本。一旦启动脚本,您就可以从脚本编辑器运行该脚本,然后在电子表格上会出现一个对话框提示,因此请确保此时切换回电子表格。
您还可以通过输入以下代码从菜单中运行它:
function onOpen(){
SpreadsheetApp.getUi().createMenu('Search Menu')
.addItem('Find and Move Files', 'findAndMoveFiles')
.addToUi()
}
您将需要将其保存到脚本编辑器,然后选择它并运行一次,以使菜单进入电子表格。下次打开电子表格时,它也会显示在电子表格中。
也请在“脚本编辑器”的帮助菜单中签出所有功能。