OldMunkiPackages.py 文件源码

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

项目:OldMunkiPackages 作者: aysiu 项目源码 文件源码
def trash_old_stuff(trashlist, trashpath, newpath):
    if isinstance(trashlist, list):
        for old_location in trashlist:
            # Get the subfolders needed to be created
            path_within_destination=os.path.relpath(old_location, trashpath)
            # Create what will be the destination path
            new_location=os.path.join(newpath, path_within_destination)
            # Make sure all the relevant subfolders exist in the destination
            if not os.path.exists(os.path.dirname(new_location)):
                os.makedirs(os.path.dirname(new_location))
            # Even though we've been double-checking paths all along, let's just make one last check
            if os.path.exists(old_location) and os.path.isdir(newpath):
                os.rename(old_location, new_location)
                logging.info("Moving %s to %s\n" % (old_location, new_location))
            else:
                logging.error("One of %s or %s does not exist\n" % (old_location, new_location))
    else:
        logging.error("%s is not a valid list\n" % trashlist)

# Function that checks paths are writable
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号