def reparent(newparent, oldpath):
'''when copying or moving a directory structure, you need to re-parent the
oldpath. When using os.path.join to calculate this new path, the
appearance of a / root path at the beginning of oldpath, supplants the
newparent and we don't want this to happen, so we need to make the oldpath
root appear as a child of the newparent.
:param: str newparent: the new parent location for oldpath (target)
:param str oldpath: the path being adopted by newparent (source)
:returns: (str) resulting adoptive path
'''
if oldpath[0] in (posixpath.sep, ntpath.sep):
oldpath = '.' + oldpath
return os.path.join(newparent, oldpath)
评论列表
文章目录