命令:os
用到的:os.walk os.listdir
写的爬虫爬的数据,但是又不知道进行到哪了,于是就写了个脚本来统计文件的个数
#统计 /home/dir/ 下的文件夹个数 import os path ="home/dir" count = 0 for fn in os.listdir(path): #fn 表示的是文件名 count = count+1 print count
获取文件夹下的文件的个数:
import os path = os.getcwd() #获取当前路径 count = 0 for root,dirs,files in os.walk(path): #遍历统计 for each in files: count += 1 #统计文件夹下文件个数 print count #输出结果