如何使用DocsList将文件复制到特定文件夹中? [英] How to copy a file into a specific folder using DocsList?

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

问题描述

我试图使用此代码将Google电子表格复制到特定的文件夹中。

  var targetFolder = DocsList.createFolder(Testing ); 
var mainDocBlob = DocsList.getFileById(docId)。getBlob();
var newMainDoc = targetFolder.createFile(mainDocBlob);

但是生成的文件是一个Pdf文件,而不是源文件的电子表格。



如何使用DocsList执行此操作,并始终获取与源文件相同的文件类型。



谢谢

解决方案

正如,谷歌文档不是常规意义上的文件,没有必要使用getBlob来复制它们,因为它们实际上并没有有Blob ...(他们实际上没有'大小',也没有使用Gdrive中的空间,原因相同!)

相反,您应该使用(as在David的答案中提到) addToFolder()



从这一点开始,您的文件将被移至相应的文件夹。如果您需要在根文件夹中有一个副本,然后制作一份副本,但根据您访问文件的方式,这并不总是必要的,因为您始终可以使用所有项目浏览您的Google驱动器,并在其中查看其所有项目相应的文件夹(以及它们所属的文件夹的名称)。

如果文件已经在文件夹中,则它将显示为属于这两个文件夹并且再次您可以选择保持原样,或使用 removeFromFolder()将其从原始文件夹中移除。



I知道这与其他答案似乎有点多余,但我只希望它能让Google的组织变得更加清晰。


I am trying this code to copy a Google spreadsheet into a specific folder

var targetFolder = DocsList.createFolder("Testing");
var mainDocBlob = DocsList.getFileById("docId").getBlob();
var newMainDoc = targetFolder.createFile(mainDocBlob);

But the resulting file is a Pdf file instead of a spreadsheet as the source was.

How to do this right using DocsList and always getting the same type of file as the source is.

Thanks

解决方案

As mentioned in this other post answer, Google docs are not "files" in the common sense, there is no need to use getBlob to copy them as they don't actually have Blob... (and they don't actually have a 'size' nor use space in your Gdrive for the same reason !)

Instead you should use (as mentioned in David's answer) addToFolder().

From this point your file will be moved to the corresponding folder. If you need to have a copy in your root folder then make a copy of it but depending on how you access your files this is not always necessary as you can always explore your Google drive using "All Items" where you see all items in their corresponding folders (and the name of the folder they belong to as well).

If the file was already in a folder then it will appear as belonging to both folders and again you can choose to leave it as it is or remove it from the original folder using removeFromFolder().

I know this seems a bit redundant with the other answers but I just hope it makes things more clear on the organization of Google drive.

这篇关于如何使用DocsList将文件复制到特定文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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