google-apps-script - Google 驱动器脚本异常“异常:无法检索下一个对象:迭代器已到达末尾。”
问题描述
H,我创建了一个脚本,如果文件存在,我会在其中检查谷歌驱动器上的目标文件夹我获取文件的 ID,否则我在那里创建文件并获取 ID,我面临的问题是它有时可以完美运行,但是有时我收到异常“异常:无法检索下一个对象:迭代器已到达末尾。” 我可以确认该文件位于目标文件夹中,但仍会发生此异常。如果创建文件有任何延迟,我已经使用了睡眠功能。我也检查了其他人分享的几个问题。 列出文件时出现“无法检索下一个对象:迭代器已结束”错误
//Copy File to Destination
function CopyFileNew(file,dest,source,filename){
var destination = DriveApp.getFolderById(dest);
var filecheck = destination.getFilesByName(filename);
if(!filecheck.hasNext()){
destination.addFile(file);//file is undefined
Utilities.sleep(2000);
var newfile=destination.getFilesByName(filename);
if(newfile.hasNext()){
Utilities.sleep(2000);
return "https://drive.google.com/open?id="+newfile.next().getId(); // HERE I GET THE ERROR
}
}
else{
return "https://drive.google.com/open?id="+filecheck.next().getId();
}
}
解决方案
推荐阅读
- java - 使音频循环更快
- linux - 断点未命中 - 在 Visual Studio 中使用 C++ 进行 Linux 开发
- react-native - TypeError:未定义不是一个对象(评估'navigator.geolocation.requestAuthorization')
- .net - 有没有办法从图中过滤异常值,因此在交叉表中,我不应该看到异常值
- c++ - 加载 std::queue 的更有效方法
与元素? - javascript - React 为什么仍然将函数传递给组件?
- php - 无法使用 Ajax 运行 sql 查询
- java - 如何从列表适配器刷新布局/上下文(我认为这是我需要的)
- visual-studio - 从智能感知中永久过滤属性/方法?
- php - 如何防止用户检查页面和编辑表单元素的值?