简体   繁体   中英

How can I use a Google Apps Script to add multiple Google Docs to a Google Drive folder?

I have a list of Google Document URLs (about 700 of them) and need to add them to a Google Folder so that they are all in one space because currently they are owned by hundreds of different users.

I've seen a few postings on how to do the inverse of this: Generate a list of URLs from the contents of a folder. This has been helpful, but it seems this task is much more difficult.

This is what I've tried, and it doesn't seem to be working:

var doc = DocumentApp.openById('1sQGds0kyeO66ZiMiJlsKkHPcqjySPy5q0dWShc2irts'),
docFile = DriveApp.getFileById( doc.getId() );
DriveApp.getFolderById('0B7yp85g7j5ZHbVlEUmNGX2w0M1k').addFile( docFile );
DriveApp.getRootFolder().removeFile(docFile);

it doesn't error check and may timeout... but it is a start. You would add the fileIds in Column A.

 function makeCopyFromId() { var sheet = SpreadsheetApp.getActiveSheet(); var startRow = 2; // First row of data to process var numRows = 700; // Last row to process. var dataRange = sheet.getRange(startRow, 1, numRows, 5) var data = dataRange.getValues(); var destFolder = DriveApp.getFolderById("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); for (i in data) { var row = data[i]; var ssId = row[0]; Logger.log(ssId); // check the log to see if they all complete- var destSpreadsheet = SpreadsheetApp.open(DriveApp.getFileById(ssId).makeCopy("",destFolder)) //copies each file. }} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM