Code snippet: AppsScript – Copy files, folders, subfolders in Drive

This is a really quick post for the greater good… I have been looking into a solution to satisfy a customer requirements (really strange ones) about their need to automatically create daily versions of all files on a certain G Suite account they have…

The good thing about this is they are all using the Business license (the unlimited Drive storage) so it does not matter really how large the files goes on the Drive. I just need to make sure the destination folder does not get downloaded for offline access (hence the need for archiving).


I checked for some samples of code around and I found a lot of scripts with only one common problem: They cannot work well with sub-folders… So I tried to create my own and I came up with this script…


This will work with files and folders and sub-folders well. It will copy first any files that are existing in the root of the source folder, then work its way through the sub-files and folders… All you need is to follow the instructions at the end of this post to get it running:

To run the script:

  1. Create a new script, copy and paste the code in it
  2. Save and enter a name for the project
  3. Click Resources -> Advanced Google services…
  4. Enable the Drive API, then save
  5. Select the function ‘run’, and run it

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.