fileList.txt
C:\exist1
C:\noexist
C:\exist2
C:\exist3
上記のようなフォルダパスが書かれたテキストファイルを読み込み、そのフォルダにあるファイル数をそれぞれ取得する。
fileCounter.py
import os, os.path
folders = open("fileList.txt", "r")
for folder in folders:
if os.path.exists(str(folder).rstrip()):#読み込めるフォルダ内のファイル数を表示
filenum=len(os.listdir(str(folder).rstrip()))
print (folder)
print (filenum)
else: #読み込めないフォルダを表示
print("can not read path")
print(folder)
folders.close()