Google云端硬盘:将文件移至文件夹 [英] Google Drive: Move file to folder
问题描述
我想了解当您选择谷歌驱动器脚本时列出的moveFileToFolder脚本 http: //www.google.com/script/start/ (点击开始脚本,然后选择创建脚本菜单中的驱动器选项)
I want to understand the moveFileToFolder script that is listed as an example when you select google drive scripts http://www.google.com/script/start/ (click "Start Scripting" then select "Drive" option in "Create script for" menu)
代码如下。我的问题是如何改变这个代码,以便它可以用来将文件Austin移动到文件夹Texas中?这是假设文件奥斯汀是一个谷歌文档,目前正在坐在我的主要谷歌驱动器文件列表和文件夹德克萨斯州目前也坐在我的主要谷歌驱动器列表。
The code is below. My question is how would I alter this code so that it could be used to move the file "Austin" into the folder "Texas"? This is presuming that the file "Austin" is a google doc which is currently sitting in my main google drive file list and the folder "Texas" is also currently sitting in my main google drive list.
关于在驱动器中移动文件还有一些其他帖子,我了解主要概念,但似乎无法成功获取文件或文件夹ID。任何帮助非常感谢?
There are a few other posts regarding moving files in drive and I understand the main concepts but I can't seems to successfully procure the file or folder ID's. Any help greatly appreciated?
/**
* This script moves a specific file from one parent folder to another.
* For more information on interacting with files, see
* https://developers.google.com/apps-script/class_file
*/
function moveFileToFolder(fileId, targetFolderId) {
var targetFolder = DocsList.getFolderById(targetFolderId);
var file = DocsList.getFileById(fileId);
file.addToFolder(targetFolder);
};
推荐答案
现在我有相同的任务并使用此代码:
now I had the same task and used this code:
var file = DriveApp.getFileById(fileId)
var folder = DriveApp.getFolderById(folderId);
folder.addFile(file);
这篇关于Google云端硬盘:将文件移至文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!