Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在google drive中创建子目录_Python_File_Google Drive Api_Subdirectory - Fatal编程技术网

Python 如何在google drive中创建子目录

Python 如何在google drive中创建子目录,python,file,google-drive-api,subdirectory,Python,File,Google Drive Api,Subdirectory,我正在学习一个教程,该教程要求我在一个文件夹中创建一个子目录。在本教程中,它演示了如果文件是本地文件,如何执行此操作;但是,我的文件在谷歌硬盘上。我希望能够使目录如下所示: My Drive └── Colab Notebooks └── Web scraper └── dataset_dogs_vs_cats ├── test │ ├── cats

我正在学习一个教程,该教程要求我在一个文件夹中创建一个子目录。在本教程中,它演示了如果文件是本地文件,如何执行此操作;但是,我的文件在谷歌硬盘上。我希望能够使目录如下所示:

My Drive
  └── Colab Notebooks
        └── Web scraper
              └── dataset_dogs_vs_cats
                      ├── test
                      │   ├── cats
                      │   └── dogs
                      └── train
我只想创建“test”下2个子目录的文件夹。以下代码是如果文件是本地文件,您将如何执行此操作:

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

我的问题是,我如何修改它以使其与Google Drive一起工作?

我知道您希望使用python Drive API在驱动器中创建文件夹,也许您将来会希望填充这些文件夹。在这种情况下,您可以在这里看到有关如何执行的示例。要设置授权脚本,可以使用作为参考。如果你还有疑问,请问我任何问题