Skip to main content

Reading and editing Windows PATH.

Project description

GitHub tag (latest by date) PyPI PyPI - Downloads GitHub

🛁 pathtub

Simple python functions for reading and editing Windows PATH variables.

    ✅ Ensuring that an folder exists in Path.
    🧽 Cleaning the PATH (duplicates, removed folders, sorting)
    ✏️ Adding or removing folders to/from Path (temporary or permanently)

Installing

pip install pathtub

Usage

✅ Ensuring folder is in PATH

What is ensure()?

ensure(folder) checks if folder is in Process PATH

  • If folder is in Process PATH, does nothing
  • If folder is not in Process PATH, adds it to Process PATH
  • If folder is not in Process PATH and permanent=True, adds also to the User PATH (permanent) or System PATH (permanent, needs admin rights).

Example code for ensure()

  • It is safe to call ensure() every time you load your script, for example. It only does something if folder is not found in your process PATH.
  • The last "trailing" backslash of folder (if any) is ignored when comparing to any other folders.
from pathtub import ensure
dll_folder = r'C:\my favourite\dlls'
# 1) Check Process PATH, i.e. os.environ['PATH']
# 2) Add to Process PATH (temporary) if not found
ensure(dll_folder)

Example code for ensure() with permanent addition

  • You may also make the addition permanent (& visible to other processes).
  • Also this is safe to call every time script is starting.
from pathtub import ensure
dll_folder = r'C:\my favourite\dlls'
# 1) Check Process PATH
# 2) Add to Process PATH if not found
# 3) Add also to User PATH (permanent), if 2) happens
ensure(dll_folder, permanent=True)

🧽 Cleaning PATH

Cleaning paths means

  1. Removing duplicates from the PATH (trailing backslash neglected)
  2. Removing empty entries from PATH
  3. Sorting alphabetically (optional, Default: True)
  4. Removing folders that do not exist (optional, Default: True)
  5. Removing from "User" list the ones that are in the "System" list (optional, default: True)

Screenshots of User PATH before and after clean:

User PATH

Code example for clean

from pathtub import clean
clean()

# possible parameters:
# clean(sort=True, remove_non_existent=True, remove_user_duplicates=True)

Rest of the docs

Did not find what you were looking for? See the Rest of the docs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathtub-1.1.1.tar.gz (6.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page