在colab中访问本地文件夹
Access local folder in colab
我想创建一个函数来在 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"
我想创建一个函数来在 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"