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 is to identify those files and organize them. This process is driven from the sheets created by Finding where Drive hosting is being used in Sites, but they could be created by any process if you have to do this for a platform other than Sites.

The report

You get 1 report, which summarizes all the files that need attention into one row per file, with a reorganization of the layout of the hosted files so they can easily be loaded to the new hosting place – whichever method you choose. At this stage, it’s independent of that. The filePath below is how the files will be re-organized. No files are copied yet – that’ll happen in the next phase, but this is how it proposes to re-organize the googledrive hosted files. Note that it works with both and variations.

This report is used as input to the next phase, Copying to new host location

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.



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

Some notes on the settings

  • This will create a new sheet, so sheetId and sheetFiles say where.
  • treatments are how to handle situations and to organize the files
    • filename is a template to construct the new file name- It can be any text you like, and you can also include the {id} and {name} somewhere in the new file name, where id and name are the values for the current file.
    • path is an output path describing the folder structure the new files will end up. Here you can use any text plus {id},{name},{drivePath} and {mime} where id and name refer to the name and id of the current file, drivePath is the path of its current folder and mime is an abbreviated form of its mime type.
    • failOnMissing – if a file is missing and this is true it will stop processing
    • missingText – is the text to use for a filename if it the file is missing

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
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.