In BASH, to create a file and the parent directories it may have, it can be done install -D /dev/null file_name
.
For example:
install -D /dev/null /var/tmp/an-example/example_file.txt
would create the full directory structure, /var/tmp/an-example/, and the empty file, example_file.txt.
I wonder if in Python there's an easy pythonic way to do the same, apart from using subprocess...
I was checking, and I found myself an easy way just after posting...
Valid for Python >= 3.5
from pathlib import Path
# ...
# creates directories structure, like mkdir -p <directories> would do
Path(file_with_path[:file_with_path.rfind("/")]).mkdir(parents=True, exist_ok=True)
# creates the empty file, as touch <filename> would do:
Path(file_with_path).touch()