google-drive-api - Colab如何获取现有文件的文件ID
问题描述
我从 colab for ml 开始,将文件从我的谷歌驱动器导入笔记本时遇到问题。假设我的pretrained_vgg19.mat
驱动器中有一个文件,例如drive/jupyter/pretrained_vgg19.mat
. 从驱动器导入文件的代码片段说我需要使用看起来像laggVyWshwcyP6kEI-y_W3P8D26sz
. 我如何获得这个 file_ID?
解决方案
有关命令,请参阅 PyDrive文档ListFile
:
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
# Auto-iterate through all files in the root folder.
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
print('title: %s, id: %s' % (file1['title'], file1['id']))
现在您需要做的就是调整搜索参数,因为您已经知道文件的标题。请参阅文档。
file_list = drive.ListFile({'q': "name='pretrained_vgg19.mat' and trashed=false"}).GetList()
for file in file_list:
print('%s' % (file['id']))
请注意,文件可能具有相同的文件夹名称和文件名,因为您可以在 Google Drive 中创建多个具有相同路径的文件夹。如果有可能,您将在列表操作中返回多个文件,并且需要使用其他一些标准才能选择正确的文件。
推荐阅读
- css - 为什么滚动时这个固定的标题会移动?
- outlook-addin - 打包使用 Yeoman 创建的 Outlook 加载项
- hyperledger - 调用 Composer 休息服务器时跨域请求被阻止
- java - Spring - server.connection-timeout 不起作用
- php - 无法在 PhpStorm 中使用 Symfony 安装作曲家
- java - 错误:验证失败,退出主清单和属性 uses-feature#20000@glEsVersion 在 AndroidManifest.xml
- python - 使用 GPU 加速和 cuda 进行 fft 的最佳方法
- c# - SSIS WebClient() 下载文件脚本任务问题
- django - 如何创建在时间表中实施课程的 django 模型?
- r - 使用“officer”包插入外部文档