python小练——找出指定目录下小于指定字节的文件,输出到文本文件
2011-08-10 11:51
309 查看
代码:
import os
import sys
def showsmallfiles(dir):
v=os.listdir(dir)
for i in v:
d="%s/%s"% (dir,i)
if os.path.isdir(d):
showsmallfiles(d)
else:
if os.path.getsize(d) < int(sys.argv[2]):
logger(d)
#logfile
def logger(text):
f=open('d:/python/log.txt','a')
f.write(text+'\r\n')
f.close()
if len(sys.argv)<3:
print('arguments is invalid')
sys.exit()
showsmallfiles(sys.argv[1])
调用方式:
python listsmallfile.py d:/python 1000
import os
import sys
def showsmallfiles(dir):
v=os.listdir(dir)
for i in v:
d="%s/%s"% (dir,i)
if os.path.isdir(d):
showsmallfiles(d)
else:
if os.path.getsize(d) < int(sys.argv[2]):
logger(d)
#logfile
def logger(text):
f=open('d:/python/log.txt','a')
f.write(text+'\r\n')
f.close()
if len(sys.argv)<3:
print('arguments is invalid')
sys.exit()
showsmallfiles(sys.argv[1])
调用方式:
python listsmallfile.py d:/python 1000
相关文章推荐
- java创建目录+文本文件+输出文本到指定文件
- python ( os , path , sys ) 找出指定目录下的所有文件,并求出大小且排序
- python输出指定目录下所有文件(全路径),并核对md5码
- python查找指定目录下所有文件,以及改文件名的方法
- Python中实现从目录中过滤出指定文件类型的文件
- Python批量重命名指定目录下文件的两种方法
- 如何查看某个指定目录下的所有文件,只要显示其文件名,并把它输出
- python实现指定目录下批量文件的单词计数:串行版本
- 将一个指定目录下的Java文件的绝对路径存储到一个文本文件中。
- python 文件和目录 当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径。
- Python实现扫描指定目录下的子目录及文件的方法
- Python读取指定目录下指定后缀文件并保存为docx
- python实现指定目录下批量文件的单词计数:并发版本
- Python删除指定目录下过期文件的2个脚本分享
- Python 遍历目录找出包含指定字符串的文件夹
- 【Java基础】遍历指定目录并且找出包含指定名字的文件
- linux下用python统计某个目录下指定后缀文件的个数
- Java基础知识强化之IO流笔记14:递归之输出指定目录下所有java文件绝对路径的案例
- Python获取指定目录下文件数量及总大小
- Python/ArcPy遍历指定目录中的MDB文件