def path_advance(thepath, sep=os.sep):
'''generator to iterate over a file path forwards
:param str thepath: the path to navigate forwards
:param str sep: *Default: os.sep* - the path separator to use
:returns: (iter)able of strings
'''
# handle a direct path
pre = ''
if thepath[0] == sep:
pre = sep
curpath = ''
parts = thepath.split(sep)
if pre:
if parts[0]:
parts[0] = pre + parts[0]
else:
parts[1] = pre + parts[1]
for part in parts:
curpath = os.path.join(curpath, part)
if curpath:
yield curpath
评论列表
文章目录