判断字符串是否以某字符串开头或结尾

import os,stat


# str.startswith()

# 获取当前目录下以.py 或者.sh结尾的文件
l = [name for name in os.listdir('/shells/') if name.endswith(('.sh','py'))]
print(l)

# 获取文件的权限
for file in l:
    print(oct(os.stat('/shells/%s'%file).st_mode))
    os.chmod(file,os.stat(file).st_mode | stat.S_IXUSR)

猜你喜欢

转载自www.cnblogs.com/ray-mmss/p/10465596.html