python multiple directory, Python multiple directory creation in best 2 ways, Shopinson, Shopinson

Today in Python Programming Language I will be illustrating how to create python multiple directory but 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, Python multiple directory creation in best 2 ways, Shopinson, Shopinson
Multiple directory using Python

How to create a python multiple directory

I will illustrate how to do so using two simple methods

1st method: Creating multiple directories using python script

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

python multiple directory, Python multiple directory creation in best 2 ways, Shopinson, Shopinson
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 : creating multiple directories using python script

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)
0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

shopinson-logo-32

©2020 Shopinson: complete guide to programming language

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account