List all title + ID of a googledrive content folder in Google Colab

我是研究僧i 提交于 2019-12-13 20:45:46

问题


Given the timing of Google Colab, I usually store my Google Drive activities in a DDMMYY folder (Day, month and year). Every day the content is stored like this. Images, code, drafts, etc.

I mount Google Drive using the default form of Google Colab and not PyDrive

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

Is there any way to generate title + ID of all folder contents of the day (DDMMYY) in a list (csv, xml or json)?


回答1:


This metadata is stored in extended file attributes. You can retrieve them using the xattr command.

Here's a complete example: https://colab.research.google.com/drive/16ylOxW_AyON1CMvjlT8rBAlDTpnR5fEa

The key bits:

# 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:'


来源:https://stackoverflow.com/questions/55652925/list-all-title-id-of-a-googledrive-content-folder-in-google-colab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!