質問

I have been trying all day and I found this: http://www.jellybend.com/2012/12/19/monitor-google-drive-folders-with-google-apps-script/

The attached script worked only partially for me. It doesn't respond to change to the subfolders even there are files inside the subfolders (eg. rename/delete the subfolder). It also seems to have errors if I delete and re-add the same file to the folder again, it just doesn't email me for the newly added "old file".

I also found this: https://developers.google.com/drive/v2/reference/changes/list#examples

but unfortunately I am not really sure what those parameters are and I am just inexperienced in writing something like that.

Any help will be greatly appreciated! Thanks!

役に立ちましたか?

解決

The file monitoring code at that link, is an Apps Script bound to a Sheet. An Apps Script can be bound to a Sheet, Doc, Form or Site. An Apps Script can also be a stand alone application. So, any code you may want to write, does not need to be in a spreadsheet.

An Apps Script can be set up to have a Time-driven event trigger.

Event Trigger Apps Script

There is also a Script Service to build Clock Triggers.

ClockTriggerBuilder Class

Using Time Driven Event Trigger, or a Clock Trigger you could use the getSize() method to return the amount of disk space used by the item:

Class - Folder - getSize Method

// This example logs the first file's size in bytes
 // Note: This can also be used on a folder to get the size of its contents
 var file = DocsList.getAllFiles[0];
 Logger.log(file.getSize());

Of course, you would need to know what the original size of the folder or file was, and so you would need to store the current size somewhere. You could create a file for storing that information, or use the built in database that Apps Script has.

For storing your historical folder or file information you could use ScriptDB.

ScriptDB

Quote:

ScriptDB is a JavaScript object database for Google Apps Script. Each script project gets a database, which the script can use to save, update, and search JavaScript object data.

You could write historical file and folder info to a spreadsheet or document also.

Depending on who owns the file, and who is accessing the file, permissions would need to be granted, or you'd need to use oAuth2 to authenticate who has access to the file and folder information.

If you can't write all the code yourself, you could set up a shared Apps Script file, or find some other way to have people collaborate on the project.

他のヒント

I've been researching this on my own for some time and came up with a script bound to a spreadsheet as well. Hope it can help someone, as it seems that a lot of people are looking for something similar. My script is monitoring a folder and sends notification to all the current viewers of the folder as soon as there is new file added. Trigger to run the script could be set depending on the needs of the user. In my case hourly worked just fine.

Spread Sheet with the script: https://docs.google.com/spreadsheets/d/1CzVADjUTT2d9Y5OGDOnv37mCaO49kPt4RmnyZgzjTKA/edit#gid=0

If you would like to try this script just make sure you are logged in with your google account when you open the link and you should be able to make a copy of the spreadsheet.

This Google Script will send an email notification to you or other email addresses when a file in a Google Drive folder has been added, renamed, changed, or modified. http://baumbach.com/google-script-2/

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top