To create a new folder in Google drive through python script using Pydrive Module














































To create a new folder in Google drive through python script using Pydrive Module



Steps :
  1. The all important code :
    1. from pydrive.drive import GoogleDrive
    2. drive = GoogleDrive(gauth)

    3. # To create a new folder
    4. folder_name = input("Name the Folder : ")
    5. folder = drive.CreateFile({'title' : folder_name, 'mimeType' : 'application/vnd.google-apps.folder'})
    6. folder.Upload()
  2. Line 1 above code just imports GoogleDrive class from pydrive.drive library
  3. Line 2 creates an object drive of GoogleDrive class
  4. In line 5 we are asking for the folder name from the user
  5. line 6 is creating a new folder in root directory with the given folder name from the user.
  6. In line 7 we are uploading the newly created folder in the root directory.



Following is the output instance in Google drive after running the above code in a suitable ide :


Comments