Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

613
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!