判斷字符串是否以某字符串開頭或結尾


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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM