0

I want to make 79 folder in my drive and want folder name is a number 1 to 79. this is my code. I used Google colab

import os
for i in range(1,80):
  folder = "/content/drive/My Drive/project/Dataset"
  os.makedirs(folder[i])

Please Help. My code can be change if you have any thought.

Nara Nart
  • 43
  • 5
  • 5
    How about `os.makedirs(f"{folder}/{i}")` – j1-lee Nov 12 '22 at 19:18
  • You're code is trying to create 79 folders (your title states it should be 80) and it's trying to create folders for each of the letters as you loop through the individual characters of your string. – Mushroomator Nov 12 '22 at 19:22

1 Answers1

1

Use:

import os

folder = "/content/drive/My Drive/project/Dataset"
for i in range(1,80):
    os.mkdir(os.path.join(folder,str(i)))
R Walser
  • 330
  • 3
  • 16
  • FileExistsError Traceback (most recent call last) in 1 for i in range(1,80): 2 folder = "/content/drive/My Drive/project/Dataset/" ----> 3 os.mkdir(os.path.join(folder,str(i))) FileExistsError: [Errno 17] File exists: '/content/drive/My Drive/project/Dataset/1' – Nara Nart Nov 13 '22 at 07:15
  • It's not work. It's show " File exists: '/content/drive/My Drive/project/Dataset/1 " – Nara Nart Nov 13 '22 at 07:17
  • It worked on mine. You probably already have that folder created. Add `os.makedirs` with `exist_ok=True`. See https://stackoverflow.com/questions/12468022/python-fileexists-error-when-making-directory – R Walser Nov 13 '22 at 07:54