Python中的内部目录计数 [英] Internal directory count in Python

查看:62
本文介绍了Python中的内部目录计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i want to make code using python from which i can count the directories which is in a directory and the files in it.i am getting number of files and filenames by using listdir() function and count also by using len(data) function.but i have directories in a directory & in that i have files. i am using below code.<br>please guide me for that
<pre><br>

ans =(Dir_name 56)的例子



我尝试过:



example of ans=(Dir_name 56)

What I have tried:

import os
img_folder_path = ("C:/Users/Uname/Desktop")
dirListing = os.listdir(img_folder_path)
  print(dirListing)
  print(len(dirListing))

推荐答案

python文件或目录 - Google搜索 [ ^ ]


除了 Richard 的解决方案之外,我建议你看一下os.walk [ ^ ](参见代码示例)。
I addition to Richard's solution, I would suggest you having a look at os.walk[^] (see the code sample).


这篇关于Python中的内部目录计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆