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

356
Views
Move Folders in Google Drive Using Google Apps Script

I was wondering if someone could take a look at this for me.

  • The goal

My company has a ton of client folders on google drive that are full of content (files and folders). I'm trying to take all of the existing content, and move it into a newly created folder within each client folder named "old client work".

  • The issue

When I run the code, there's an issue with moving folders. Creating the "old client work" folder works fine, as does moving existing files into it. But the code runs into an error when trying to move folders.

  • The code

Here is the code I have:

function createOldClientWorkFolder() {
    var clientContentFolder = DriveApp.getFolderById("IDhere");
    var clientFolders = clientContentFolder.getFolders();
    while(clientFolders.hasNext()) {
        var client = clientFolders.next();
        var oldWorkFolder = client.createFolder('Old Client Work');
        var clientContentFiles = client.getFiles();
        var clientContentFolders = client.getFolders();
        while (clientContentFiles.hasNext()) {
              var fileToMove = clientContentFiles.next();
              fileToMove.moveTo(oldWorkFolder)
        }

        while (clientContentFolders.hasNext()) {
              var folderToMove = clientContentFolders.next();
              folderToMove.moveTo(oldWorkFolder)
        }


    }

}

Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

(Since you haven't provided a log/error message I'm guessing here, but I encountered something similar a while ago while trying to move folders so I thought this might help.)

moveTo requires that you have permission to the object that you're trying to move itself. Could there be a possibility that your app script doesn't have the write permission to the actual client folder? (moveTo modifies the parent property of the folder object you're trying to move, so you also read write permission, not just read).

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!