Languages
[Edit]
EN

Python - create multiple subfolders

0 points
Created by:
OneCricketer
460

In this article, we would like to show you how to create multiple subfolders in Python.

Quick solution:

Note:

The exist_ok parameter was added in Python 3.5. Set it on True so you won't get FileExistsError if the directory exists.

 

Practical example

Edit

In this example, we create a directory with multiple (N) subfolders in our project directory using makedirs() method from os module.

if you want to create multiple subfolders outside the project folder, you need to specify the full path:

result:

Python - create multiple subfolders - before
Python - create multiple subfolders - before

 

Python - create multiple subfolders - after
Python - create multiple subfolders - after

References

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - file operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join