鸦鸦 发表于 2019-2-17 09:49:45

Python 查找Linux文件

  #!/usr/bin/python
#encoding:utf-8
import os
FileList=[]
def ScanFile(Dir,Suffix):
if os.path.isdir(Dir):
items=os.listdir(Dir)
for names in items:
if os.path.isfile(Dir+'/'+names) and names.endswith(Suffix):
FileList.append(Dir+'/'+names)
else:
if os.path.isdir(Dir+'/'+names):
ScanFile(Dir+'/'+names,Suffix)
DIRNAME="/tmp"
ScanFile(DIRNAME,".log")
if len(FileList)!=0:
print(FileList)
else:
print("查找文件不存在")
http://i2.运维网.com/images/blog/201812/06/85686ea22daa1da5fe65e428966a9da9.png
  执行结果:
http://i2.运维网.com/images/blog/201812/06/3f1bd493febe07f18bbccfb5b228f2b4.png



页: [1]
查看完整版本: Python 查找Linux文件