Reading and editing Windows PATH.
Project description
🛁 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
- It is safe to call
ensure()
every time you load your script, for example. It only does something if the dll_folder is not found in your processPATH
. - The last "trailing" backslash (if any) is ignored when comparing any two 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)
- 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)
- The Process PATH is loaded from parent process or from the permanent (User/System) PATH when process is started. For more info, see: Windows PATH variables.
- "Real life" example using ensure.
- Full documentation of
ensure()
is in the source code (pathtools.py).
🧽 Cleaning PATH
Cleaning paths means
- Removing duplicates from the PATH (trailing backslash neglected)
- Removing empty entries from PATH
- Sorting alphabetically (optional, Default: True)
- Removing folders that do not exist (optional, Default: True)
- Removing from "User" list the ones that are in the "System" list (optional, default: True)
Screenshots of User PATH before and after clean:
Code example for clean
from pathtub import clean
clean()
# possible parameters:
# clean(sort=True, remove_non_existent=True, remove_user_duplicates=True)
- For more detailed example, see Full example of pathtub.clean
- Full documentation of
clean()
is in the source code (pathtools.py).
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.0.tar.gz
(6.3 kB
view hashes)