I have successfully created a single in the previous post on Creating Single directory using now we are going to create multiple instead.

How to create a multiple directory with Python

I will illustrate how to do so using two simple methods

1st method

I will use os.makedirs() instead of os.makedir() to create a multiple directories instead of single directory see the blow code snippet

import os os.makedirs('shopinson/users/timers') 

this will create folders as shown below

create multiple directories instead of single directory see the below code snippet
create multiple directories instead of single directory see the below code snippet

To create the multiple directories with file permissions defined use the below python code snippet

import os os.makedirs('shopinson/users/timers',mode=0o444)

2nd Method

We are going to be using python pathlib.Path to create multiple directories see the code snippet below

import pathlib  p = pathlib.Path('shopinson/users/timers') p.mkdir(parents=True)

LEAVE A REPLY

Please enter your comment!
Please enter your name here