python 目录文件操作 os模块
2015-07-13 15:08
1021 查看
编写一个search(s)的函数,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出完整路径
#-*- coding:utf-8 -*- import os import sys def search(s,dir='.'): result=[] print s for x in os.listdir(dir): if os.path.isfile(x) and (s in x): result.append(os.path.join(dir,x)) elif os.path.isdir(x): result+=(search(s,os.path.join(dir,x))) return result if __name__ == '__main__': print search(sys.argv[1])
相关文章推荐
- python正则相关
- Python学习笔记——一些常用函数、常见错误总结
- python 模块==命名空间?
- python 打开一个文件并随机读取文件某一行
- Multiprocessing vs Threading Python
- python 之 模拟GET/POST提交
- Python Paste.deploy 笔记
- Python thread pool similar to the multiprocessing Pool?
- python 随机数
- python 计算器
- Python.Paste指南之Deploy
- python 读取文件
- python 函数参数
- Python3.2官方文件翻译-工具列表和十进制浮点计算
- python第一个爬虫
- python第三方库系列之十八--python/django test库
- Python三种结构
- 【Python 学习手册笔记】动态类型简介
- strategy pattern in Python
- Python: Unable to find vcvarsall.bat 解决方法