Python 查找Linux文件

#!/usr/bin/python#encoding:utf-8import osFileList=[]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):Fil...

#!/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("查找文件不存在")

执行结果:

本文标题为:Python 查找Linux文件

基础教程推荐