Create a new director in google drive from colab
To create a new directory in Google Drive from Google Colab, you can use the following steps:
-
First, make sure you have the
google.colab
library installed in your Colab environment. If you don't have it installed, you can install it by running the following command:!pip install google-colab
-
Next, import the
google.colab
library and authenticate with your Google account:from google.colab import auth auth.authenticate_user()
-
Once you're authenticated, you can use the
drive
module to interact with your Google Drive account. Create a new directory by running the following command:from google.colab import drive drive.mount('/content/drive')
This will mount your Google Drive account to the
/content/drive
directory in your Colab environment. -
Now, you can create a new directory in your Google Drive account by running the following command:
import os os.mkdir('/content/drive/My Drive/new_directory')
Replace
new_directory
with the name you want to give to your new directory. -
To verify that the directory has been created, you can run the following command:
!ls /content/drive/My Drive/new_directory
This should list the contents of your new directory.
That's it! You should now have a new directory in your Google Drive account that you can access from your Colab environment.
Here's the complete code:
!pip install google-colab
from google.colab import auth
auth.authenticate_user()
from google.colab import drive
drive.mount('/content/drive')
import os
os.mkdir('/content/drive/My Drive/new_directory')
!ls /content/drive/My Drive/new_directory
Note: Make sure you have the necessary permissions to create directories in your Google Drive account. If you're using a shared drive, you may need to have the necessary permissions to create directories in that drive.