Provide Directory

0.1.2 · active · verified Wed Apr 15

The `provide-dir` library is a lightweight utility that ensures a given directory path exists, creating all necessary parent directories if they don't. It's built on top of `os.makedirs` and offers a simplified interface. Currently at version 0.1.2, it follows an infrequent but steady release cadence, with updates typically several months apart.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `provide_dir` to create a nested directory structure. It will create `temp_test_dir/my/nested/directory` and print the resulting path. The `os.environ.get` ensures it's runnable without specific environment setup.

from provide_dir import provide_dir
import os

# Define a test directory path
base_dir = os.environ.get('TEST_BASE_DIR', 'temp_test_dir')
dir_path = os.path.join(base_dir, 'my', 'nested', 'directory')

print(f"Attempting to create: {dir_path}")

# Create the directory and all its parents
created_path = provide_dir(dir_path)

print(f"Directory ensured at: {created_path}")
print(f"Does the directory exist? {os.path.isdir(created_path)}")

# Clean up (optional)
# import shutil
# shutil.rmtree(base_dir)

view raw JSON →