Last active
July 4, 2016 19:04
-
-
Save taliaga/e74f072015472866fa8fe315401d0c0f to your computer and use it in GitHub Desktop.
Filter PATH in windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from __future__ import print_function | |
import os | |
# Original PATH | |
original_path = os.environ['PATH'] | |
print('*'*80) | |
print('Your current PATH:') | |
print(original_path) | |
# Filter PATH | |
print('*'*80) | |
print('Filtering PATH...') | |
new_path = [] | |
for p in original_path.split(';'): | |
if not os.path.isdir(p): | |
print('{} no longer exits'.format(p)) | |
else: | |
if p in new_path: | |
print('{} was repeated'.format(p)) | |
else: | |
new_path.append(p) | |
# Filtered PATH | |
print('*'*80) | |
print('New PATH:') | |
print(';'.join(p for p in new_path) + ';') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment