hanyeah 专注于AS

python获取某个目录下特定后缀名的文件的文件名及大小

最开始是想用批处理来做的,批处理完全做得到,只是不会写。后来想到了用python。

电脑上装一种脚本语言挺实用的,可以用来做一些常用的测试或批量操作。(使用python3.4.3)

import os  
from os.path import join, getsize

homedir = os.getcwd()
print(homedir)

s=""
for root,dirs,files in os.walk(homedir):
	for name in files:
		if ".swf" in name:
			size=getsize(join(root,name))
			print(join(root,name),size)
			s+=join(root,name)+"\t"+str(size)+"\n"
f = open("out1.txt",'w')
f.write(s)
f.close()
input()

实现遍历python文件所在目录下(以及子目录)的所有后缀名为“.swf”的文件,将文件名(包含路径)和问价大小写入到out1.txt文件中。


源码打包下载

2016年3月3日 | 发布:hanyeah | 分类:python | 评论:0

发表留言: