About 740,000 results
Open links in new tab
  1. Create a directory in Python - GeeksforGeeks

    Oct 8, 2024 · To create directories, you can use the os.mkdir() and os.makedirs() functions. To create a single directory, you can use the os.mkdir() function. Output. If you need to create nested directories, use the os.makedirs() function. Output.

  2. python - How to create new folder? - Stack Overflow

    Using os.path.join in all cases assures that your paths will be formed correctly for the platform the script is being run on. Have you tried os.mkdir? You might also try this little code snippet: mypath = ... os.makedirs(mypath) makedirs creates multiple levels of directories, if needed.

  3. python - How do I create a directory, and any missing parent ...

    Apr 24, 2023 · Use os.path.dirname(p) On Python ≥ 3.5, use pathlib.Path.mkdir: For older versions of Python, I see two answers with good qualities, each with a small flaw, so I will give my take on it: Try os.path.exists, and consider os.makedirs for the creation. os.makedirs(directory)

  4. How to Create a Directory in Python - AskPython

    Apr 24, 2020 · We will learn several ways to create a directory in Python. Python os module is a module used to deal with and interact with the underlying operating systems and the files. The os module contains various in-built methods to create directories in the system. Among them, the popular ones are the mkdir () method and the makedirs () method in Python.

  5. Creating a Directory in Python – How to Create a Folder

    Mar 23, 2023 · As mentioned earlier, to work with directories in Python, you first need to include the os module. To do so, add the following line of code to the top of your file: The code above will allow you to use the os.mkdir() method to create a new single directory. The os.mkdir() method accepts one argument – the path for the directory.

  6. Python: Creating Directories - A Comprehensive Guide

    Jan 24, 2025 · To create a directory, you can use the Path.mkdir() method. The parents=True argument in the mkdir() method of pathlib allows you to create all the necessary parent directories if they don't already exist. Before creating a directory, it's often a …

  7. How to Create a New Directory in Python - Tutorial Kart

    To create a new directory in Python, we use the os.mkdir() or os.makedirs() function from the built-in os module. The mkdir() function creates a single directory, whereas makedirs() can create nested directories. Additionally, Python 3.5+ provides pathlib.Path.mkdir() for an object-oriented approach. 1. Creating a Single Directory Using os.mkdir()

  8. Create a directory with mkdir(), makedirs() in Python

    Apr 19, 2025 · In Python, you can create new directories (folders) using the os.mkdir() and os.makedirs() functions. While os.mkdir() creates a single directory, os.makedirs() is more convenient when you need to create a directory and all required parent directories at once. All sample code in this article assumes that the os module has already been imported.

  9. Creating a Directory and its Parent Directories in Python - Stack …

    Aug 24, 2023 · In Python, we often need to interact with the file system, whether it's reading files, writing to them, or creating directories. This Byte will focus on how to create directories in Python, and more specifically, how to create a directory and any missing parent directories. We'll be exploring the os.mkdir and os.makedirs functions for this purpose.

  10. Different ways to create a folder in Python - Medium

    Mar 31, 2023 · In this article, we will explore three different methods for creating a folder in Python. The os.mkdir() function is a built-in Python function that creates a new directory with the...

  11. Some results have been removed
Refresh