0
votes

I am trying to figure out google apps script, which will move files from one parental folder to the subfolders based on part of files name. I am using one mail merge script to automatically create letters and documentation. Every file has an unique code in his name (for ex. file name is: "Lepic - KN - 28541 - 2013.pdf", where the "28541 - 2013" is the unique code) and for every unique code exist one subfolder (folder name: "Lepic - 28541 - 2013").

So in parental folder it basically looks like this:

  • Lepic - KN - 28541 - 2013.pdf
  • Lepic - RV - 28541 - 2013.pdf
  • Novak - KN - 15427 - 2013.pdf
  • Michal - Vozidla - 11125 - 2012.pdf
  • etc etc ...

Now I have to move every file to his folder manually, which is really annoying even with only 20+ files.

Does anybody know how to modifity this script (listened in google script examples) to sort files to folders based on theirs unique code automatically?

function moveFileToFolder(fileId, targetFolderId) {
var targetFolder = DocsList.getFolderById(targetFolderId);
var file = DocsList.getFileById(fileId);
file.addToFolder(targetFolder);
};

Thank you!

1

1 Answers

0
votes

Not clear what you are asking. Are you asking how to move a file in Apps Script, or how to set up automation? If the latter, look at triggers. Write your script to seek out and move any files needing to be moved, and then assign a timer trigger to repeat that action at some reasonable interval.