我尝试使用pythongoogledriveapi为一个文件构建一个远程路径。给定一个路径,比如/folderA/FolderB/folderC/文件.txt我想在驱动器上创建folderA,然后在其中创建folderB,然后在B中创建folderC,然后将文件上传到folderC。在
我有一个简短的循环:
currentParent = pathStartID
for aFolder in pathArray:
thisFoldersID = self.createRemoteFolder(aFolder, parentID = currentParent)
currentParent = thisFoldersID
我首先在驱动器根目录中创建folderA,folderA的ID是'pathStartID'。pathArray包含folderB和folderC的名称。在
^{pr2}$看起来像这样:
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']
在根目录下创建的父文件夹并不是我想要的每一个原因。在
有人能看出我做错了什么吗?或者有更简单的方法吗?在
似乎只是设置父级的属性名错误。尝试:
相关问题 更多 >
编程相关推荐