Google Apps Script that moves a file into a folder with the same name

时间:2017-12-18 05:32:01

标签: javascript google-apps-script drive google-apps-script-editor

I am EXTREMELY new to coding and really don't know where to start with this. I am trying to figure how to move about 1200 .pdf files into specific folders. I am trying to do the following:

Move File "AAA.12-17" into Folder "AAA"
Move File "BBB.12-17" into Folder "BBB"
Move File "CCC.12-17" into Folder "CCC" and so on.

I run a 1200 page .pdf report that I split into individual one page files, save, and move into the specific folders in my Drive.

I've been researching scripts that move files in Google drive but can't figure out how to move specific files into specific folders. I appreciate all the help I can get on this.

Thanks in advance.

Willie

1 个答案:

答案 0 :(得分:1)

Folders don't actually exist on a Google drive. Files are indentified by an id number. Then they are tagged or labelled with what we see as folder names. A file can have multiple tag/labels associated with it (and it can appear in multiple folders at once).

So to "move" a file to a "folder" - what you're really doing is deleting a label (old folder name), and adding a new one (new folder name).

There's a similar question that has been answered that you can look at: moving-files-in-google-drive-using-google-script

Also see Google's documentation. Look at addFile and removeFile on this page: https://developers.google.com/apps-script/reference/drive/folder