Python工作笔记-统计文件夹内只有1个文件的文件夹

文件

只有1文件夹里面有1个文件

 

程序运行后截图如下:

 

源码如下:

import os

def GetErrorFileList(dir):
	list=[]
	
	for dirpath,dirnamesList,filenamesList in os.walk(dir):
		count=0
		for filename in filenamesList:
			count+=1
		if count==1:
			list.append(dirpath)
			pass
		
		count=0
		for dirname in dirnamesList:
			count+=1
		
		if count==1:
			list.append(dirpath)
		pass
	return list;
	pass

if __name__=='__main__':
	
	list=GetErrorFileList("D:\\MyTemplate")
	f=open("data.txt","w")
	for fileDir in list:
		f.write(fileDir+"\n")
		
	f.close()

 

©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页