https://blog.csdn.net/kongxx/article/details/51939247

https://pymotw.com/2/pwd/

# 文件是否可写
def is_writeable(filepath):
    guest = pwd.getpwnam('Guest')

    uid = guest.pw_uid

    gid = guest.pw_gid

    s = os.stat(filepath)

    mode = s[stat.ST_MODE]

    return (((s[stat.ST_UID] == uid) and (mode & stat.S_IWUSR > 0)) or 
            ((s[stat.ST_GID] == gid) and (mode & stat.S_IWGRP > 0)) or 
            (mode & stat.S_IWOTH > 0)) 

0 Comments latest

No comments.