I would like to ask you to create a folder within a folder within a folder.

Asked 2 years ago, Updated 2 years ago, 13 views

First, the folder creation code is

import os

def folder(dir):
        try:
            if not os.path.exists(dir):
                os.makedirs(dir)
        except OSError:
            print('error: up.' + dir)
 folder('./1/2/3/4/5/6/7/8/9/10')

This creates folder 2 in folder 1, folder 3 in folder 2, and folder 10 in folder 9.

I want to make a repeat sentence for sentence or while, so how should I put it in?

python

2022-09-20 17:25

1 Answers

import os

path = os.getcwd()
for i in range(0, 3):
  path = os.path.join(path, str(i))
  print(f'we will mkdir {path}')
  os.mkdir(path)


2022-09-20 17:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.