summaryrefslogtreecommitdiffstats
path: root/Lib/macpath.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-07-23 02:28:32 (GMT)
committerGuido van Rossum <guido@python.org>1996-07-23 02:28:32 (GMT)
commita48bf799774eb6f8d4fe3e80f1890fb3246a787a (patch)
tree8226f3927fb35e9ea7af1140ff6e122cb8b027a9 /Lib/macpath.py
parent54afb3bf60c690fc4f0984217134dc4fd9956800 (diff)
downloadcpython-a48bf799774eb6f8d4fe3e80f1890fb3246a787a.zip
cpython-a48bf799774eb6f8d4fe3e80f1890fb3246a787a.tar.gz
cpython-a48bf799774eb6f8d4fe3e80f1890fb3246a787a.tar.bz2
Added splitext()
Diffstat (limited to 'Lib/macpath.py')
-rw-r--r--Lib/macpath.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py
index 71748c9..c45ecbf 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -46,6 +46,28 @@ def split(s):
return s[:colon-1], s[colon:]
+# Split a path in root and extension.
+# The extension is everything starting at the last dot in the last
+# pathname component; the root is everything before that.
+# It is always true that root + ext == p.
+
+def splitext(p):
+ root, ext = '', ''
+ for c in p:
+ if c == ':':
+ root, ext = root + ext + c, ''
+ elif c == '.':
+ if ext:
+ root, ext = root + ext, c
+ else:
+ ext = c
+ elif ext:
+ ext = ext + c
+ else:
+ root = root + c
+ return root, ext
+
+
# Split a pathname into a drive specification and the rest of the
# path. Useful on DOS/Windows/NT; on the Mac, the drive is always
# empty (don't use the volume name -- it doesn't have the same