用代碼將很多文件進行整理,由於文件很多,不知道文件夾下到底有多少文件,於是就寫了統計文件的個數的代碼:
統計/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 #輸出結果