Make multiple directories based on a List using Python Last Updated : 15 Jan, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to learn how to make directories based on a list using Python. Python has a Python module named os which forms the core part of the Python ecosystem. The os module helps us to work with operating system folders and other related functionalities. Although we can make folders/directories directly on the system here we will see how to make many folders from a list given in Python which is less time-consuming. Here, we will see how to create nested directories with os.makedirs(). Make Multiple Directories Based on a List in PythonBelow are the ways by which we can create multiple directories based on a list in Python: Create Folders in the Same Directory Where Python is InstalledIn this example, we have taken a list of elements. Then we iterate through each element in the list. Since we have not mentioned any root directory, the os module makes a folder of each element of the list in the directory where our python ide is installed. Python3 import os list = ['folder10','folder11','folder12', 'folder13', 'folder15'] for items in list: os.mkdir(items) Output: Create a Folder Automatically in PythonDeclare the root directory where we want to create the list of folders in a variable. Initialize a list of items. Then iterate through each element in the list. The os module makes a folder of each element of the list in the directory where our python ide is installed. Use os.path.join() to join the items of the list as a folder to the root directory. Then use os.mkdir() to create a single directory in each iteration through the list. Python3 import os root_path = 'Documents/tmp/year/month/week/day/hour' list = ['car', 'truck', 'bike', 'cycle', 'train'] for items in list: path = os.path.join(root_path, items) os.mkdir(path) Output: Create a List of Directories With Subfolders Inside a Given Root DirectoryFirst, import the partial function from the functions module and initialize the root directory and list of directories. Use the partial function and pre-fill it with the root directory to create the path for creating a list of folders inside. Then again with the help of partial function and os.makedirs() method prefills the make_directory function. Iterate through the list of items given. In each iteration call the make_directory method with each list item as a parameter to create a directory. Python3 import os from functools import partial root_directory = 'Documents/abc' list = ('one/sub_file_1', 'two/sub_file_2', 'three/sub_file_3') concat_root_path = partial(os.path.join, root_directory) make_directory = partial(os.makedirs, exist_ok=True) for path_items in map(concat_root_path, list): make_directory(path_items) Output: Snapshot of created subfolder given below. Related Concept os Moduleos.mkdir(path)os.path.join(root_path, path)partial(function,argument1,argument2,...)os.makedirs(path) OS Library - Bulk Directories Creation Comment More infoAdvertise with us Next Article How to merge multiple folders into one folder using Python ? R rijushree100guha Follow Improve Article Tags : Python Python directory-program Practice Tags : python Similar Reads How to merge multiple folders into one folder using Python ? In this article, we will discuss how to move multiple folders into one folder. This can be done using Python's OS and Shutil module. Approach:Get the current directory and the list of the folders you want to merge.Loop through the list of folders and store their content in a list. Here, we have stor 4 min read Listing out directories and files in Python The following is a list of some of the important methods/functions in Python with descriptions that you should know to understand this article. len() - It is used to count number of elements(items/characters) of iterables like list, tuple, string, dictionary etc. str() - It is used to transform data 6 min read List all files of certain type in a directory using Python In python, there are several built-in modules and methods for file handling. These functions are present in different modules such as os, glob, etc. This article helps you find out many of the functions in one place which gives you a brief knowledge about how to list all the files of a certain type 3 min read How to List all Files and Directories in FTP Server using Python? FTP ( File Transfer Protocol ) is set of rules that computer follows to transfer files across computer network. It is TCP/IP based protocol. FTP lets clients share files. FTP is less secure because of files are shared as plain text without any encryption across the network. It is possible using pyt 2 min read How to Create Directory If it Does Not Exist using Python? In this article, We will learn how to create a Directory if it Does Not Exist using Python. Method 1: Using os.path.exists() and os.makedirs() methods Under this method, we will use exists() method takes path of demo_folder as an argument and returns true if the directory exists and returns false if 2 min read How to move all files from one directory to another using Python ? In this article, we will see how to move all files from one directory to another directory using Python.  In our day-to-day computer usage we generally copy or move files from one folder to other, now let's see how to move a file in Python: This can be done in two ways:Using os module.Using shutil m 2 min read Like