addToFolder():如果删除了原始版本,则会删除文件的副本版本 [英] addToFolder(): The copy version of the file is deleted, if the original version is deleted
问题描述
我几天前开始使用google脚本开发,最近加入stackoverflow。我有一个问题与addToFolder()函数。我有以下代码段将我的新电子表格复制到我的Google云端硬盘中的文件夹(测试/工作表):
I started doing development with google scripts few days ago and recently joined stackoverflow. I have a problem with addToFolder() function. I have the following piece of code that copies my new spreadsheet into a folder (test/sheets) in my Google Drive:
var ss = SpreadsheetApp.create("test");
var ssID = ss.getId();
DocsList.getFileById(ssID).addToFolder(DocsList.getFolder("test/sheets"));
我的问题是,现在我有两个版本的同一个文件驱动器文件夹,另一个在test / sheets文件夹中),每当我尝试删除任何副本,其他副本也被删除。有没有办法删除旧的文件并保留新的一个OR是有办法在所需的文件夹中创建该文件吗?
My problem is that now I have 2 versions of the same file (one in the root of my Google Drive folder and the other in test/sheets folder), whenever I try to delete either of the copies, the other copy is deleted as well. Is there a way to delete the old file and keep the new one OR is there a way to create the file in the desired folder in first place?
编辑:
感谢您的快速回应。我玩了几个小时,但仍有问题将文件复制到目标文件夹。问题是,即使我使用makeCopy方法的文件,仍然addToFolder是唯一的选项提到文件夹。这样最终在目标文件夹中有标记的文件名。
我有与复制方法相同的问题。
这是我的新代码:
thanks for you quick response. I played with this for couple of hours but still have problem copying the file to the destination folder. The problem is that even when I use makeCopy Method of the file, still addToFolder is the only option to mention the folder. Again this ends up having the tagged filename in the destination folder.
I had the same problem with the copy method.
Here is my new Code:
var SetLocationFile = "icompare/sheets/stocks"
var FolderID = DocsList.getFolder(SetLocationFile);
var FileID = DocsList.getFileById(ssID);
FileID.makeCopy("test3").addToFolder(FolderID);
推荐答案
Google文档\Google云端硬盘中的文件夹实际上是标签。当您将文件添加到文件夹test / sheets时,您不会制作文件的副本,您只需将标签test / sheets附加到它。现在,同一个文件显示在test / sheets文件夹中(即在所有带有标签test / sheets的文件的列表中)和在根目录中。如果您希望制作文件的副本,则应使用复制方法。 (如果我只是误解了您的问题,请让我知道。)
Folders in Google Docs\Google Drive are actually tags. When you "add" a file to the folder "test/sheets", you do not make a copy of your file, you just attach the tag "test/sheets" to it. Now the same file is shown both in the "test/sheets" folder (i.e. in the list of all files with the tag "test/sheets") and in the root. If you wish to make a copy of the file, you should use the copy method. (Please let me know if I just misunderstand your question.)
这篇关于addToFolder():如果删除了原始版本,则会删除文件的副本版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!