Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
Copiar carpeta de Google Drive

Estoy tratando de modificar un código que encontré en este sitio web para que sea un poco más personalizado para mi proyecto y un poco más fácil de usar para mis compañeros de trabajo.

Estoy tratando de obtener los ID de carpeta para las carpetas de origen y de destino de las celdas de la hoja de cálculo. Estoy seguro de que hice el código correctamente para esta parte, pero recibo un error de excepción de ID cuando intento ejecutar el código. Cuando coloco directamente los ID en el código, usando comillas para convertirlos en cadenas, donde actualmente tengo resSource y resTarget, el código funciona perfectamente.

No puedo entender cómo usar una variable para pasar la ID de la carpeta a la función correctamente... ¿alguien puede ayudarme?

 function onOpen(){ createMenu() } function createMenu (){ const ui = SpreadsheetApp.getUi() const menu = ui.createMenu("Copy Folders") menu.addItem("Copy Folder", "copyFolder") menu.addToUi() } /** * Copies all the files in a folder to another one. */ function copyFolderContents_(source, target) { // Iterate files in source folder const filesIterator = source.getFiles() while (filesIterator.hasNext()) { const file = filesIterator.next() // Make a copy of the file keeping the same name file.makeCopy(file.getName(), target) } } /** * Recursivelly copies a folder and all its subfolders with all the files */ function copyFolder_(toCopy, copyInto) { // Makes the new folder (with the same name) into the `copyInto` const newFolder = copyInto.createFolder(toCopy.getName()) // Copy the contents copyFolderContents_(toCopy, newFolder) // Iterate any subfolder const foldersIterator = toCopy.getFolders() while (foldersIterator.hasNext()) { const folder = foldersIterator.next() // Copy the folder and it's contents (recursive call) copyFolder_(folder, newFolder) } } /** * Entry point to execute with the Google Apps Script UI */ function copyFolder() { // Get the folders (by ID in this case) const toCopy = DriveApp.getFolderById(resSource) const copyInto = DriveApp.getFolderById(resTarget) var app = SpreadsheetApp; var ss = app.getActiveSpreadsheet(); var activeSheet = ss.getActiveSheet(); var sourceText = activeSheet.getRange("A2").getValue(); var resSource = sourceText.toString; console.log(resSource); var targetText = activeSheet.getRange("B2").getValue(); var resTarget = targetText.toString; console.log(resTarget); // Call the function that copies the folder copyFolder_(toCopy, copyInto) }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

function copyFolderContents_(source, target) { const ss = SpreadsheetApp.getActive(); const sh = ss.getSheetByName("SheetName"); const vs = sh.getRange(2, 1, sh.getLastRow() - 1, 2).getValues(); vs.forEach(r => { let source = DriveApp.getFolderById(r[0]); let target = DriveApp.getFolderById(r[1]); const files = source.getFiles() while (files.hasNext()) { const file = files.next() file.makeCopy(file.getName(), target) } }); } 
A B
ID de fuente ID de destino
about 4 years ago · Juan Pablo Isaza Relatório

0

En la función copyFolder, el código pasa resSource y resTarget como parámetros en un par de declaraciones, pero estas variables se declaran después de ellas.

Intenta moverte

 // Get the folders (by ID in this case) const toCopy = DriveApp.getFolderById(resSource) const copyInto = DriveApp.getFolderById(resTarget)

justo antes

 // Call the function that copies the folder copyFolder_(toCopy, copyInto)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda