睿智微信

import os
import stat


wechat_file_dir = "E:/WeChat Files/wxid_xxx/FileStorage/File/"


def set_attrib(file):
    s = os.stat(file).st_file_attributes
    if s & stat.FILE_ATTRIBUTE_READONLY:
        os.chmod(file, stat.FILE_ATTRIBUTE_NORMAL)
        print("Set file \"%s\" to writeable." % file)


def recursive_search(target, top=""):
    if target == "":
        target = top
    else:
        if top[-1] != '\\' and top[-1] != '/':
            top = top + "\\"
        target = top + target
    os.chdir(target)
    dirs = [f for f in os.listdir() if os.path.isdir(f)]
    files = [f for f in os.listdir() if os.path.isfile(f)]
    for d in dirs:
        recursive_search(target=d, top=target)
    for f in files:
        set_attrib(f)


if __name__ == '__main__':
    recursive_search(top=wechat_file_dir, target="")
    print("\n\nfinished.")