I have been out of the programming world for some time and so am looking for any help that you may be able to provide.
I am trying to create a Google drive set up that automatically creates a new folder that is titled "mm/dd/yyyy" when it receives it's first upload of the day. The files will then continue to automatically be assigned to that folder until a 12.01am the next day, which is when another new folder would be generated once an upload is completed on that day...etc etc. Ideally the script would not create a mandatory folder every day as there will not be uploads everyday, it would only take action once the "command" of a file, photo, video is being uploaded.
Any help would be a massive help. Thanks guys.
P.s no I do not have a script to share I am relearning as we speak.
You can create a programmable pattern for this.
Create a folder using Files:create api. See documentation
Set a logic when you want to upload a file/photo/video using Files:insert or Files:update. See Files Insert and Files update.
When there's an update from your folder created, you can use the property:
enter image description here
Pass that property as date format "mm/dd/yyyy" to Files:update:
enter image description here
This will trigger again the Files:create api.
For more informations:
Uploading Files
Work with Folders
Related
I continue to expand my project - the problem described at Selecting a subfolder to upload based on the response has been successfully resolved. Therefore, I am looking for a solution to the following problem. The respondent is to submit the file using the form. How to send him a link to this file (with download permissions but not editing) or send the file itself (e.g. by e-mail).
Folders are created based on the responses from the form, so at the stage of creating the form, I do not know the names and IDs of these folders.
I understand that you already have developed scripts for «emailing a file that is already on Google Drive or for sending a link to such a file», and your goal is to run such scripts when a file is uploaded to a Form. If my understanding of your scenario is correct, then you are very close to reaching your goals.
First of all let me clarify that the files uploaded on Form populate a Drive folder automatically. You can see in your main Drive folder (My Drive) that there is one folder for your form, and inside that folder there is one additional folder for every question in your form that requires a file upload. Please keep in mind that all respondent users will share the same folders.
Knowing the fundamentals discussed above, you only need one additional function to connect the new files in your Drive folder to your already existing scripts for mailing the files. To do so you can set up a form submit trigger that fires your scripts. To connect your scripts with the forms responses folder, you should copy the folder ID into your function. Let me know if you need further clarifications with this approach.
I am looking for a sample script or hint to fix the following problem. I want the file sent from the form to go to one of the folders (created earlier) depending on the respondent's answer.
More precisely, the respondent selects the group to which he is assigned and files from people in this group go to the same folder.
I found such an example
Google Form Upload files to specific new folder based on the value submitted
however, multiple subfolders with the same name are created
EDIT !
My mistake. The script works perfectly. This is a good solution.
I would like to allow my students to send me one or more files directly to my google drive via a form where they would just enter their name and choose the file(s) to send (drag and drop would be great). A folder with their name would be created in a specific folder on my drive and a warning email would be sent to me. Do you think this is feasible with google script? Thanks in advance.
An example here but paying ...
I've checked and Google Forms already allows for a File Upload kind of question (with drag and drop too).
It automatically creates a folder in your Google Drive (altough it doesnt create a folder for every student) (example here) and in the spreadsheet that it automatically generates there is a permanent link to that file (example here).
If that's not what you are looking for and you need the 'Folder per student' feature then yes, you can use google apps script to move files in folders quite easily.
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.
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/
I'm playing with the Google Drive API and one thing that I keep wondering about is IDs in the case of an arbitrary file (non-Google App) like an image.
If a user is working locally, offline and they turn off the Google Drive client. And then they make some changes to a file, let's say they rename it, move it from one folder to the next and edit it.
Will the ID remain the same when the client comes back on, or will it break? I imagine the client will interpret either one or all of the move, rename and edit as delete and new file.
Would appreciate any help here!
The file id (within Google Drive) remains the same from the original creation to its deletion.