2
我正尝试使用Python Google Drive API为文件构建远程路径。给定一个路径,说/folderA/FolderB/folderC/theFile.txt我想在Drive上创建folderA,然后在folderB中,然后在B中,在将文件上传到folderC之前创建folderC。构建路径 - Google Drive SDK
我有一个短循环:
currentParent = pathStartID
for aFolder in pathArray:
thisFoldersID = self.createRemoteFolder(aFolder, parentID = currentParent)
currentParent = thisFoldersID
予先在驱动器根目录中创建folderA,和folderA的ID是 'pathStartID'。 pathArray包含folderB和folderC的名称。
createRemoteFolder()
看起来是这样的:
def createRemoteFolder(self, folderName, parentID = None):
# Create a folder on Drive, returns the newely created folders ID
body = {
'title': folderName,
'mimeType': "application/vnd.google-apps.folder"
}
if parentID:
body['parentsCollection'] = [{'id': parentID}]
root_folder = driveFileMan.client.files().insert(body = body).execute()
return root_folder['id']
但由于某种原因在谷歌硬盘的根目录中创建的每个文件夹,而不是在父文件夹像我想要的。
任何人都可以发现我做错了什么吗?还是有更简单的方法来做到这一点?
我应该已经发现了 - 花了好几年时间挠着我的头看着这个!太好了,谢谢你的帮助,那就是诀窍:) – Cian 2013-03-11 20:04:51