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

615
Visualizações
google appscript to move folder content to another folder

I am new at this and not programmer or a coder.

I am trying to make google app script to move folder content to another folder in google drive

I came across this link

I am using below code and it runs without error, but the files are not moved.

function myFunction() {
var source_folder = DriveApp.getFolderById('1fMCHA4-b2a2BQjO0VD2dd5m4V5WvXz9D')

var dest_folder = DriveApp.getFolderById('1LbZchJflfcnOKqSPYCdGcFTI_7AAVJIi')

function moveFiles(source_folder, dest_folder){

  var files = source_folder.getFiles();

  while (files.hasNext()) {

    var file = files.next();
    dest_folder.addFile(file);
    source_folder.removeFile(file);

  }
}
}

Can someone advise.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try:

function myFunction() {

  const source_folder = DriveApp.getFolderById('1fMCHA4-b2a2BQjO0VD2dd5m4V5WvXz9D')
  const dest_folder = DriveApp.getFolderById('1LbZchJflfcnOKqSPYCdGcFTI_7AAVJIi')

  // Call the function:
  moveFiles(source_folder, dest_folder)

  function moveFiles(source_folder, dest_folder) {

    const files = source_folder.getFiles()

    while (files.hasNext()) {

      const file = files.next()
      file.moveTo(dest_folder)

    }

  }

}

Rather than copy and delete each file, just move it!

The main problem you had was that you were not calling your function. You had only defined it.

Learn More:

  • File.moveTo()
about 4 years ago · Juan Pablo Isaza Relatório

0

Similar to the first answer but uses the Drive API to perform the move

function movefiles() {
  const sfldr = DriveApp.getFolderById('sid');
  const dfldr = DriveApp.getFolderById('did');
  const files = sfldr.getFiles()
  while (files.hasNext()) {
    const file = files.next()
    Drive.Files.update({ "parents": [{ "id": dfldr.getId() }] }, file.getId(), null, { supportsAllDrives: true });
  }
}

Drive.Files.update

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