LaVOZs

The World’s Largest Online Community for Developers

'; python - How to create subdirectories in google drive - LavOzs.Com

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.

Related
How do I merge two dictionaries in a single expression in Python?
How do I check if a list is empty?
How do I check whether a file exists without exceptions?
How do I copy a file in Python?
How can I safely create a nested directory?
How do I clone a subdirectory only of a Git repository?
How do I sort a dictionary by value?
How do I include a JavaScript file in another JavaScript file?
How do I list all files of a directory?
How to read a file line-by-line into a list?