Google Apps脚本:如何在文件夹中创建文件? [英] Google Apps Script: How do I create a file in a folder?

查看:96
本文介绍了Google Apps脚本:如何在文件夹中创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Apps脚本,可以创建多个文件并将它们移动到一个文件夹中。有没有办法将文件直接放在一个文件夹中,或者我必须首先获取文件,然后将其复制到适当的文件夹,然后像下面这样从根文件夹中删除它:

I have an Apps Script that creates multiple files and moves them into a folder. Is there a way to place the a file directly in a folder or do I first have to get the file then copy it to the appropriate folder and then removing it from the root folder like this:

folder=DocsList.createFolder("MyFolder");
var file=DocsList.createFile(blob);
file.addToFolder(folder);
file.removeFromFolder(DocsList.getRootFolder());

这个问题是,如果你打开Drive,你会看到文件首先放在根目录文件夹然后移动到MyFolder。所以在执行removeFromFolder之前有一点滞后。

The problem with this is that if you open up Drive you see the file being first placed in the root folder then moved to MyFolder. So there is a bit of a lag until the execution of removeFromFolder.

推荐答案

刚刚测试了下面的代码:

Just tested the following code

function Test() {
  DocsList.createFolder('Folder1').createFolder('Subfolder1').createFile('File1', 'Empty');
}

它按预期工作,即创建一个新的 File1在新创建的文件夹 My Drive \Folder1 \Subfolder1 文档。

It works as expected, i.e. created a new File1 document in newly created folder My Drive\Folder1\Subfolder1.

这篇关于Google Apps脚本:如何在文件夹中创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆