mik*_*keP 6 python search file
如何在linux中使用python搜索可执行文件?可执行文件没有扩展名,并且与具有不同扩展名的文件一起位于文件夹中.谢谢
编辑:我的意思是搜索是获取所有可执行文件的文件名,并将它们存储在列表或元组中.谢谢
要在Python中执行此操作:
import os
import stat
executable = stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
for filename in os.listdir('.'):
if os.path.isfile(filename):
st = os.stat(filename)
mode = st.st_mode
if mode & executable:
print(filename,oct(mode))
Run Code Online (Sandbox Code Playgroud)