[ appscript ] move file to target folder in Google Drive

 var fileId = "whateverFileId";
var target_folder_id = "whateverTargetFolderId";
var file = DriveApp.getFileById(fileId)
var target_folder = DriveApp.getFolderById(target_folder_id);
target_folder.addFile(file);

Result : There will be the same file Id in two locations.

googledrivetestmovefile

ref : http://stackoverflow.com/questions/15387068/google-drive-move-file-to-folder

NOTE : If we would like to remove file from the source folder, we can use the following command.

source_folder.removeFile(file);

Example

var fileId = "whateverFileId";
var target_folder_id = "whateverTargetFolderId";
var source_folder_id = "whateverSourceFolderId";
var file = DriveApp.getFileById(fileId)
var target_folder = DriveApp.getFolderById(target_folder_id);
target_folder.addFile(file);
var source_folder = DriveApp.getFolderById(source_folder_id);
source_folder.removeFile(file);

ref : https://ctrlq.org/code/19975-move-file-between-folders

 

If we are using the SDK, the references is here.

ref : https://developers.google.com/drive/v3/web/folder#moving_files_between_folders

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s