The pathlib module offers classes representing filesystem paths with semantics appropriate for different operating systems. We can create nested directory structure suing pathlib.Path.mkdir function in Python.

Advertisement
  • On Linux:
  • On Windows:

Here:

  • parents=True: instruct to create parent directories if not available.
  • exist_ok=True: Do not throw an error if a directory already exists.

Execute the above Python script and checked for the newly created directory tree.

/dir1
└── dir2
    └── dir3

Share.
Leave A Reply


Exit mobile version