编写程序,检查并输出当前文件夹及其子文件夹中包含指定字符串的.docx、.xlsx和.pptx文档名称
时间: 2023-05-12 14:06:30 浏览: 798
您好,以下是检查并输出当前文件夹及其子文件夹中包含指定字符串的.docx、.xlsx和.pptx文档名称的 Python 代码:
```python
import os
def search_files(path, keyword):
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith(('.docx', '.xlsx', '.pptx')):
with open(os.path.join(root, file), 'rb') as f:
if keyword.encode() in f.read():
print(os.path.join(root, file))
search_files('.', '指定字符串')
```
请将代码中的"指定字符串"替换为您要查找的字符串即可。
阅读全文
相关推荐
![exe](https://img-home.csdnimg.cn/images/20241231044909.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)