首页 > 编程语言 > 详细

Python 查找Linux文件

时间:2018-12-06 20:01:38      阅读:198      评论:0      收藏:0      [点我收藏+]
#!/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文件

原文:http://blog.51cto.com/wangjun51/2327214

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!