【问题标题】:List all title + ID of a googledrive content folder in Google Colab列出 Google Colab 中 googledrive 内容文件夹的所有标题 + ID
【发布时间】:2019-09-03 07:05:25
【问题描述】:

鉴于 Google Colab 的时间安排,我通常将我的 Google Drive 活动存储在 DDMMYY 文件夹中(日、月和年)。每天的内容都是这样存储的。图片、代码、草稿等。

我使用默认形式的 Google Colab 而不是 PyDrive 来安装 Google Drive

from google.colab import drive
drive.mount('/content/gdrive',force_remount=True)

有没有办法在列表(csv、xml 或 json)中生成当天所有文件夹内容的标题 + ID(DDMMYY)?

【问题讨论】:

    标签: python google-drive-api google-colaboratory


    【解决方案1】:

    此元数据存储在扩展文件属性中。您可以使用xattr 命令检索它们。

    这是一个完整的例子: https://colab.research.google.com/drive/16ylOxW_AyON1CMvjlT8rBAlDTpnR5fEa

    关键位:

    # Installing the xattr tool.
    !apt-get install -qq xattr
    
    # Retrieving the file ID for a file in `"/content/drive/My Drive/"`:
    !xattr -p 'user.drive.id' file
    
    # Retrieving the title
    !xattr -p "user.drive.itemprotostr" created.txt | grep 'title:'
    

    【讨论】:

    • 这是一个很好的解决方案,但还不是我所期望的。我期待一个文件夹所有内容的列表,而不是一个一个地寻找。
    • 将xattr 与find -exec 结合使用,这将对所有与查找谓词匹配的文件运行命令。 See here for more.
    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多