DocsList 不再有效,已被 DriveAPI、Google App Services 和 Advanced Google services 取代。
在这里我留下我的测试代码,这段代码创建文件夹-子文件夹-google文件-pdf-并以各种方式将它们存储在文件夹和子文件夹中,希望对您有所帮助
function Drive_2015() { //busca un folder, si no lo hay lo crea y crea 2 sub carpetas un google document copiado en cada una de ellas
var name='folder de prueba';
var carpeta = DriveApp.getRootFolder().searchFolders("title contains '"+name+"'");
if (carpeta.hasNext()===true) {
while (carpeta.hasNext()) {
var folder = carpeta.next();
Logger.log(folder.getName()+' '+folder.getId());
}
}else{
var folder=DriveApp.getRootFolder().createFolder(name);
var parent=DriveApp.getFolderById(folder.getId()); // get parent folder
var folder2 =parent.createFolder('Subfolder'); // 1° way to create sub folder
var folder3=folder.createFolder(name+1);// 2° way to create sub folder (and more easy)
var doc = DocumentApp.create('Documento sta');
var sheet = SpreadsheetApp.create('Spreadsheet sta');
Utilities.sleep(300); // este retardo es para garantizar en el user-side la creacion del nuevo archivo
var files = DriveApp.getFilesByName('Documento sta');// or Id var file = DriveApp.getFileById(doc.getId());
while (files.hasNext()) {
var file = files.next();
Logger.log('ojo '+file.getName());
file.makeCopy(folder3);
file.makeCopy(folder2);
var file2=file.makeCopy(folder);
file2.setName('Acta individual del alumno')
var blob = file2.getAs('application/pdf');
var file2pdf = folder.createFile(blob);
var file2pdf = DriveApp.getFileById(file2pdf.getId());
var file2pdf=file2pdf.makeCopy(folder);
Logger.log('se creó: '+file.getName()+' en la carpeta: '+folder.getName()+' el PDF es: '+file2pdf.getId());
DriveApp.getFileById(file2pdf.getId()).setTrashed(true)
DriveApp.getFileById(docid).setTrashed(true)
}
}
}