Mukul Kumar
Mukul Kumar

Reputation: 724

Access local folder in colab

I want to create a function to read files from the folder one by one in the colab. I have tried below that i.e. I uploaded my folder into My Drive and then tried to access it from there. But still, it is showing the error.

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))]

Error-->

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`

I have crossed check that there is a folder named "resume pdf" in my drive. So How can I upload a local folder and access each file of it one by one in colab??

Upvotes: 0

Views: 1282

Answers (1)

korakot
korakot

Reputation: 40828

You mounted it at /content/gdrive, but you try to access it at /gdrive, that's the error.

Just change to

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

Upvotes: 1

Related Questions