#!/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文件


基础教程推荐
- python验证多组数据之间有无显著差异 2023-08-08
- 创建python虚拟环境(在ubuntu16.04中) 2023-09-04
- 云服务器Ubuntu更改默认python版本 2023-09-03
- 使用Pycharm创建一个Django项目的超详细图文教程 2022-09-02
- Python爬虫爬取属于自己的地铁线路图 2023-08-05
- linux 安装 python3 2023-09-03
- Python+OpenCV实战之实现文档扫描 2022-10-20
- windows下面使用多版本Python安装指定版本的虚拟环境 2023-09-04
- MySQL数据优化-多层索引 2023-08-11
- 远程和Ubuntu服务器进行Socket通信,使用python和C#(准备篇) 2023-09-05