Created
December 14, 2016 08:33
-
-
Save n0531m/fcc6adcf8e07920aedab1662fe4af3a4 to your computer and use it in GitHub Desktop.
AppsScript to copy doc if updated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This script should be stored in Drive as a AppScript file and configured to run at intervals | |
//In my case, run it every two hours and copied the doc if there was an update | |
//ID of original document | |
var srcDocId="xxxxxx"; | |
//ID of desitination Folder | |
var targetFolderId= "xxxxxx"; | |
function copyDoc() { | |
copyDocIfUpdated(srcDocId,targetFolderId,2); | |
} | |
/** | |
* src : file to poll | |
* dest : destination folder to create a copy | |
* intervalhours : how you would define fresh. | |
*/ | |
function copyDocIfUpdated(src,dest,intervalhours){ | |
var srcFile=DriveApp.getFileById(src); | |
var lastupdated=srcFile.getLastUpdated(); | |
var now= new Date(); | |
if(((now.getTime()-lastupdated.getTime())/(1000*3600))<intervalhours){ | |
var targetFolder=DriveApp.getFolderById(dest); | |
//Logger.log(file.getName()); | |
var datestr=Utilities.formatDate(new Date(), "Asia/Singapore", "YYYY/MM/dd HH:mm"); | |
var newFile=srcFile.makeCopy("[copy "+datestr+"] " + srcFile.getName(), targetFolder); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment