[SOLVED] Unable to create a path object for a folder mounted in Google Drive

I am working with Google Colab.

I have created two CSV files containing URLs and subsequent labels. However, when I am trying to download the images, I am being unable to create the path object with the path I provide for creating it.

This is the code in the notebook-

path = Path("/content/drive/'My Drive'/Datasets")
dest = path/folder
dest.mkdir(parents=True, exist_ok=True)

And this is what I get-

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/usr/lib/python3.6/pathlib.py in mkdir(self, mode, parents, exist_ok)
   1247         try:
-> 1248             self._accessor.mkdir(self, mode)
   1249         except FileNotFoundError:

7 frames
FileNotFoundError: [Errno 2] No such file or directory: "/content/drive/'My Drive'/Datasets/chhau"

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
FileNotFoundError: [Errno 2] No such file or directory: "/content/drive/'My Drive'/Datasets"

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
/usr/lib/python3.6/pathlib.py in wrapped(pathobj, *args)
    385         @functools.wraps(strfunc)
    386         def wrapped(pathobj, *args):
--> 387             return strfunc(str(pathobj), *args)
    388         return staticmethod(wrapped)
    389 

OSError: [Errno 95] Operation not supported: "/content/drive/'My Drive'"

I have successfully mounted my Drive into Colab, and can access files and folders there, just cannot create the path object necessary for downloading data.

I can see the contents of the folder, by typing-

! ls /content/drive/'My Drive'/Datasets

How do I solve this problem?

Try removing ’ ’ around My Drive. For me that worked:

path = Path("/content/drive/My Drive/Datasets")
dest = path/folder
dest.mkdir(parents=True, exist_ok=True)
1 Like

That worked! Thank you so much.
Never would have guessed.