backup.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:Frontdown 作者: pfirsich 项目源码 文件源码
def relativeWalk(path, startPath = None):
    if startPath == None: startPath = path
    # strxfrm -> local aware sorting - https://docs.python.org/3/howto/sorting.html#odd-and-ends
    for entry in sorted(os.scandir(path), key = lambda x: locale.strxfrm(x.name)):
        try:
            #print(entry.path, " ----- ",  entry.name)
            if entry.is_file():
                yield os.path.relpath(entry.path, startPath), False
            elif entry.is_dir():
                yield os.path.relpath(entry.path, startPath), True
                yield from relativeWalk(entry.path, startPath)
            else:
                logging.error("Encountered an object which is neither directory nor file: " + entry.path)
        except OSError as e:
            logging.error(e)

# Possible actions:
# copy (always from source to target),
# delete (always in target)
# hardlink (always from compare directory to target directory)
# rename (always in target) (2-variate) (only needed for move detection)
# hardlink2 (alway from compare directory to target directory) (2-variate) (only needed for move detection)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号