用代码将很多文件进行整理,由于文件很多,不知道文件夹下到底有多少文件,于是就写了统计文件的个数的代码:
统计/home/jiangt下文件夹的个数
import os
path ="home/jiangt"
count = 0
for file in os.listdir(path): #file 表示的是文件名
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 #输出结果