python 統計資料夾下的所有資料夾或檔案數目

2021-09-24 15:06:45 字數 465 閱讀 999

統計/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 #輸出結果

Python 提取資料夾下所有檔案

tensorflow版faster rcnn 訓練自己的資料集 需要提取名稱構成訓練集 train.txt 測試集 val.txt 驗證集 time 2018 12 29 10 50 author moli99 coding utf 8 import os def file name file di...

Python遍歷資料夾下所有檔案

7只遍歷當前資料夾 不遞迴遍歷 import glob dir test samples glob.glob dir print samples print len samples test 1.txt test new 2遍歷當前資料夾下所有的.txt import glob dir test s...

python檢視資料夾下所有檔案

實現檢視所有檔案,重點在於資料夾下又有資料夾時怎樣處理,這裡通過os模組來解決.方法一 通過遞迴實現遍歷所有資料夾 import os def func path for i in os.listdir path path2 os.path.join path,i 拼接絕對路徑 if os.path...