0 votes
1 view
in Python by (11.5k 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 (107k 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
asked Jun 26, 2019 in Python by Aarav (11.5k points)
0 votes
1 answer
asked Jul 18, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...