Recently, I needed a quick way to create multiple folders (now called ‘Collections’, but I will refer to them as folders since I dont like the term collections) within Google Docs. Needless to say, it would take a long time to do this by hand. I then ran into gdata-python-client, which is the Google Data APIs Python Client Library. It basically makes me look like I know what I’m doing with python, but fear not, I don’t :)
So, lets say I have a file called foldernames, within this file is all the folders I want created in google docs. Let’s take a look.
mb-pr0:c0de jgilmour$ cat foldernames
Folder1
Folder2
Folder3
Folder4
Simple, enough, right? I want 4 folders created, Folder1, Folder2, Folder3, and Folder4. But how do we get these to be created in google docs? Well first we need the gdata-python-client library installed. Installation instructions can be found in the links above, it’s pretty straight forward, then we need our code.
import gdata.docs.service
client = gdata.docs.service.DocsService()
client.ClientLogin('googledocsuser@domainhere.com', 'passw0rdgoeshere')
f = open ('/path/to/foldernames', 'r')
for line in f:
print "Creating folder: " + line,
client.CreateFolder(line,)
So, whats going on here? Well simply, we log into google docs, open the file foldernames read the file line by line, tell the user we are creating the folder, and then we call CreateFolder(line,) which creates the foldername based upon what is currently in line.
Let’s run the script and make sure everything looks ok:
mb-pr0:c0de jgilmour$ python createfolder.py
Creating folder: Folder1
Creating folder: Folder2
Creating folder: Folder3
Creating folder: Folder4
And Let’s make sure it looks ok in google docs:
Simple, right? I had to create around 80 folders, so I’m VERY happy that didn’t have to be done via the web interface!
TechSmog


Hi jgilmour,
This is exactly what I need, But it’s so difficult for me, because I’m not an coder. Can you help me?
Exactly what will I do to create multiple Google Docs Collections/Folders!
Thanks for your consideration :)
H?c Nguy?n.
I’ve done what you’ve mentioned above, but how can I create sub Collection?
Thanks ^^
Nice day, pro :)
Hi -
Glad you found it helpful, I’m not really a coder either, I just dabble :P
I believe you can pass the following:
CreateFolder(‘child-folder’, parent_folder_entry)
ie: client.CreateFolder(‘subfolder’, line,)