Question

I'm currently moving then deleting. Is it possible just to create the file in the correct folder. I don't seem to be able to make DocsList interact with DoccumentApp

var targetFolder = DocsList.getFolderById("0B2o_9r2k_45fUFpja0FRWXc4YWM"); var mynewDoc = DocumentApp.create(datasource[row][2]);

'var gFID = DocsList.getFileById(newFileID)     
 gFID.addToFolder(targetFolder);
 gFID.removeFromFolder(DocsList.getRootFolder());`
Was it helpful?

Solution

Documents within Google Apps are not particularly in a folder. We can think of folder more as labels, even though the engineers have made stride to make it look like the paradigm we are used too. So files can exist in multiple folders and creation happens in the root folder, after which you can add them to many folders as you want, and as you rightly do remove them from the root folder.

I would suggest you start using the Drive Services instead of DocList. DocList was created before Google Drive and while it continues to work, and no deprecation has been announced, it would be safer to move to Drive which offers a larger and more comprehensive API. (DocList is still labeled as experimental, while Drive is not)

OTHER TIPS

Another working variant of the code follows:

  // content, in my example, is a Blob with a mail attachment
  var doc = DriveApp.createFile(content);
  doc.setName(title);

  var fld = DriveApp.getFolderById('the destination folder id');
  fld.addFile(doc);

The new file appears under the desired folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top