python make directory mkdir in best 2 ways

0
689
Creating Multiple directories with Python scripts in two ways
Creating Multiple directories with Python scripts in two ways

Today in Python Programming Language I will be illustrating how python make directory mkdir in best 2 ways.

Before that I hope you have successfully created a single directory in the previous post on Creating Single directory with Python.

Now we are going to create multiple directories instead.

Python Multiple directory
Multiple directory using Python

How to create a python multiple directory

Hence I will illustrate how to do so using two simple methods

Firstly Creating multiple directories using python script

in the first place You can 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')

Meanwhile the code above 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

not only … but also 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 : creating multiple directories using python script

Finally 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