summaryrefslogtreecommitdiff
path: root/fs/path.py
diff options
context:
space:
mode:
authorwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-12-05 00:04:16 +0000
committerwillmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f>2010-12-05 00:04:16 +0000
commite72b070d2cf1b9dc42118d6eb48ce6c614c861e7 (patch)
treee6238eaa21181e62ec05b06e13722fe28302f3c4 /fs/path.py
parent800bcbc18feccd92e1f4e4b87f4f6706e96f08aa (diff)
downloadpyfilesystem-e72b070d2cf1b9dc42118d6eb48ce6c614c861e7.tar.gz
Added FS command line scripts
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@537 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/path.py')
-rw-r--r--fs/path.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/fs/path.py b/fs/path.py
index e42ea04..248bcfb 100644
--- a/fs/path.py
+++ b/fs/path.py
@@ -170,16 +170,57 @@ def pathsplit(path):
>>> pathsplit("foo/bar/baz")
('foo/bar', 'baz')
+
+ >>> pathsplit("/foo/bar/baz")
+ ('/foo/bar', 'baz')
"""
split = normpath(path).rsplit('/', 1)
if len(split) == 1:
return (u'', split[0])
- return tuple(split)
+ return split[0] or '/', split[1]
# Allow pathsplit() to be used as fs.path.split()
split = pathsplit
+def splitext(path):
+ """Splits the extension from the path, and returns the path (up to the last
+ '.' and the extension
+
+ :param path: A path to split
+
+ >>> splitext('baz.txt')
+ ('baz', 'txt')
+
+ >>> splitext('foo/bar/baz.txt')
+ ('foo/bar/baz', 'txt')
+
+ """
+
+ parent_path, pathname = pathsplit(path)
+ if '.' not in pathname:
+ return path, ''
+ pathname, ext = pathname.rsplit('.', 1)
+ path = pathjoin(parent_path, pathname)
+ return path, '.' + ext
+
+def isdotfile(path):
+ """Detects if a path references a dot file, i.e. a resource who's name
+ starts with a '.'
+
+ :param path: Path to check
+
+ >>> isdotfile('.baz')
+ True
+
+ >>> isdotfile('foo/bar/.baz')
+ True
+
+ >>> isdotfile('foo/bar.baz')
+ False
+
+ """
+ return pathsplit(path)[-1].startswith('.')
def dirname(path):
"""Returns the parent directory of a path.