簡體   English   中英

訪問 colab 中的本地文件夾

[英]Access local folder in colab

我想創建一個 function 在 colab 中一個一個地讀取文件夾中的文件。 我在下面嘗試過,即我將我的文件夾上傳到我的驅動器,然后嘗試從那里訪問它。 但是,它仍然顯示錯誤。

from google.colab import drive 
drive.mount('/content/gdrive')

mypath = "/gdrive/My Drive/resume pdf" #enter your path here where you saved the resumes
onlyfiles = [os.path.join(mypath, f) for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]

錯誤-->

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-15-a7a8abc74cc6> in <module>()
      1 mypath = "/gdrive/My Drive/resume pdf" #enter your path here where you saved the resumes
----> 2 onlyfiles = [os.path.join(mypath, f) for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]

FileNotFoundError: [Errno 2] No such file or directory: '/gdrive/My Drive/resume pdf'`enter code here`

我已經檢查了我的驅動器中有一個名為“ resume pdf ”的文件夾。 那么如何在colab中上傳本地文件夾並逐個訪問它的每個文件?

您將它安裝在/content/gdrive ,但您嘗試在/gdrive訪問它,這就是錯誤。

只需更改為

mypath = "/content/gdrive/My Drive/resume pdf"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM