google apps script - How do I move a spreadsheet from the root to my active folder? -


i use following code create new spreadsheet.

function addnewspreadsheetwithfoldershift() { var source = spreadsheetapp.getactive();  var ssid=source.getid(); var fileindocs = docslist.getfilebyid(ssid); var folder=fileindocs.getparents()[0]; var foldername = folder.getname(); var folderid = folder.getid(); var timezone=session.gettimezone(); var dtstamp= utilities.formatdate(new date(), timezone, 'yyyy:mm:dd  hh:mm:ss  zzz'); var user=session.geteffectiveuser().getemail(); var output_name=dtstamp+"linechecks" var ssout = spreadsheetapp.create(output_name);  // create new spreadsheet, output_name. ssout.addtofolder(folder); } 

it winds in root directory. wind in directory started from. tried using addtofolder seems files can moved using it. there way move newly created spreadsheet?

you can use docslist service move file after creation, try :

  ...   var ssout = spreadsheetapp.create(output_name);  // create new spreadsheet, output_name.   var root = docslist.getrootfolder();   var folder = docslist.getfolderbyid('your folder id');// or use getfolderbyname if want   var ssoutid = ssout.getid();   var newfile = docslist.getfilebyid(ssoutid); // begin 'move folder process'   newfile.addtofolder(folder);   newfile.removefromfolder(root);// had in 2 separate steps  } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -