-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathlist.py
53 lines (40 loc) · 1.4 KB
/
pathlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
#---------------------------------------------------------------------------------------------------
# pathlist
#
# Prints out an ordered list of all directories in the current search path environment variable.
# Duplicate entries and non-existent directories are flagged.
#---------------------------------------------------------------------------------------------------
import os
import sys
if sys.version_info[0] < 3:
sys.exit("This script requires Python 3+.");
#---------------------------------------------------------------------------------------------------
foundDuplicates = False
foundNonexistent = False
pathVar = os.environ['PATH']
pathSize = len(pathVar);
pathList = pathVar.split(';')
for n, path in enumerate(pathList):
if path == "":
continue
# Check for duplicate entries.
if pathList.count(path) > 1:
dupMarker = "+"
foundDuplicates = True
else:
dupMarker = " "
# Check for non-existent paths.
if not os.path.exists(path):
existMarker = "!"
foundNonexistent = True
else:
existMarker = " "
print ("{:2d}: {}{}{}" .format(n, existMarker, dupMarker, path))
if foundDuplicates or foundNonexistent:
print()
if foundDuplicates:
print ("+ Duplicate entries")
if foundNonexistent:
print ("! Non-existent directories")
print ("\nPath Size: {}".format(pathSize))