Skip to content

Instantly share code, notes, and snippets.

@taliaga
Last active July 4, 2016 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taliaga/e74f072015472866fa8fe315401d0c0f to your computer and use it in GitHub Desktop.
Save taliaga/e74f072015472866fa8fe315401d0c0f to your computer and use it in GitHub Desktop.
Filter PATH in windows
#!/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