The World’s Largest Online Community for Developers
I am following a tutorial that requires me to create a subdirectory in one of my folders. In the tutorial, it shows how to do it if the files are local; however, my files are on Google Drive. I want to be able to make the directory look like the following:
My Drive └── Colab Notebooks └── Web scraper └── dataset_dogs_vs_cats ├── test │ ├── cats │ └── dogs └── train
The only folders I want to create are for the 2 subdirectories under "test". The following code is how you would do it if the files were local:
# create directories dataset_home = 'dataset_dogs_vs_cats/' subdirs = ['train/', 'test/'] for subdir in subdirs: # create label subdirectories labeldirs = ['dogs/', 'cats/'] for labldir in labeldirs: newdir = dataset_home + subdir + labldir makedirs(newdir, exist_ok=True)
My question is, how do I modify this to make it work with Google Drive?
I understand that you want to create folders in your Drive using the python Drive API, and maybe you will want to populate these folders in the future. In that case, you can see here examples on how to create and populate folders. To set up an authorized script you can use the python Drive API quickstart as a reference. Please, ask me any question if you still have some doubts.