Jai Prak
Jai Prak

Reputation: 3410

move generated google Form to specific google drive folder using google apps script

I am creating a few forms using Google Apps Script which automatically generates in my root (My Drive) of my Google Drive.

I want to move these forms to a specific folder of a Shared Drive.

I googled about moving files (or any object) to another folder, most of them are suggesting that copy the file to a specific location, then delete from the source location.

But in this case, my formIds are changing which I don't want to change.

Is there any better way to move files (in my case Forms) to another location in Google Drive?

Upvotes: 0

Views: 1673

Answers (2)

JLMosher
JLMosher

Reputation: 161

the following code should work for moving any file, including forms, to a destination folder in Google Drive:

var fileId = '1234567890abcdefghijklmnopqrstuvwxyz'; //<--replace string with your file ID
var destinationFolderId = 'zyxwvutsrqponmlkjihgfedcba0987654321';//<--replace string with your destination folder ID

function moveFile(fileId,destinationFolderId) {
  var destinationFolder = DriveApp.getFolderById(destinationFolderId);
  DriveApp.getFileById(fileId).moveTo(destinationFolder);
}

Upvotes: 0

TheAddonDepot
TheAddonDepot

Reputation: 8964

As a developer you should always favor canonical sources over 3rd party tutorials that pop-up in google search. The official documentation for the Drive API has guides describing how to move files from one drive folder to the next. I suggest you start there.

Upvotes: 1

Related Questions