如何在文件夹中创建文件? [英] How do I create a file in a folder?

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

问题描述

我有一个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 is first placed in the root folder then moved to MyFolder. So there is a bit of a lag until the execution of removeFromFolder.

推荐答案

只需测试以下代码

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

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

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

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

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