In Finding where Drive hosting is being used in Sites, we created a couple of sheets by examining the hosted files referenced in a Google Site so that we could sort out the world after Google Hosting goes away. The next step was to identify those files and organize them, as described in Identifying hosted files. If you are happy with its proposals, now we can make a copy of the files that are going to be rehosted to the folder structure produced by the Identifying hosted files. Of course you could do this manually, but automating it avoids mistakes, and more importantly, keeps the work flow going for future stages.

The report

You get 1 report, which now includes the new Drive id of each of the copied files. Any required folder structured are created according to the folderPath in the report.

cUseful library

I’ll be using the cUseful library, specifically this techniques.

Here’s the key for the cUseful library, and it’s also on github, or below.

Mcbr-v4SsYKJP7JMohttAZyz3TLx7pV4j

Settings

It starts with the settings, which have been expanded to now look like this, and we’re mainly concerned with the Settings.copy section.

Some notes on the settings

  • This will create a new sheet, so sheetId and sheetCopied say where.
  • treatments are how to handle situations and to organize the files
    • removePreviousVersions – if true then any previous versions of files with the same name are removed prior to copying the new ones over
    • clearFolders – if true, this removes all files in each of the hosting folders. This will usually be false, unless you are doing some kind of a clear up.

The created folder structure

Here’s what you get, with a copy of each input file in the re-organized folder structure.

The code

It’s on GitHub, or below, or copy of developing version here. You’ll need the settings namespace at the beginning of this post too and of course the cUseful library reference.

For more like this see Google Apps Scripts Snippets
Why not join our forum, follow the blog or follow me on Twitter to ensure you get updates when they are available.