Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (11.4k points)

Is there a way to get functionality similar to mkdir -p on the shell from within Python. I am looking for a solution other than a system call. I am sure the code is less than 20 lines, and I am wondering if someone has already written it?

1 Answer

0 votes
by (106k points)

Other alternate way of writing mkdir -p is by using pathlib.path() function which is as follows:-

import pathlib pathlib.Path("/tmp/path/to/desired/directory").mkdir(parents=True, exist_ok=True)

The third parameter exist_ok was added in Python 3.5.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jun 26, 2019 in Python by Aarav (11.4k points)
0 votes
1 answer
asked Jul 18, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...