17.7.2 在硬盘上识别照片文件夹

我有一个坏习惯,从数码相机将文件传输到硬盘的临时文件夹后,会忘记这些文件夹。编程扫描整个硬盘,找到这些遗忘的“照片文件夹”,就太好了。
编写一个程序,遍历硬盘上的每个文件夹,找到可能的照片文件夹。当然,首先你必须定义什么是“照片文件夹”。假定就是超过半数文件是照片的任何文件夹。你如何定义什么文件是照片?
首先,照片文件必须具有文件扩展名.png  或.jpg。此外,照片是很大的图像。照片文件的宽度和高度都必须大于 500 像素。这是安全的假定,因为大多数数码相机照片,宽度和高度都是几千像素。
作为提示,下面是这个程序的粗略框架:
#!  python3
#  Import  modules  and  write  comments  to  describe  this  program.

for  foldername,  subfolders,  filenames  in  os.walk('C:\\'): numPhotoFiles  =  0
numNonPhotoFiles  =  0
for  filename  in  filenames:
#  Check  if  file  extension  isn't  .png  or  .jpg. if  TODO:
numNonPhotoFiles  +=  1
continue         #  skip  to  next  filename #  Open  image  file  using  Pillow.
#  Check  if  width  &  height  are  larger  than  500. if  TODO:
#  Image  is  large  enough  to  be  considered  a  photo. numPhotoFiles  +=  1
else:
#  Image  is  too  small  to  be  a  photo. numNonPhotoFiles  +=  1

#  If  more  than  half  of  files  were  photos, #  print  the  absolute  path  of  the  folder. 
if  TODO:
print(TODO)
程序运行时,它应该在屏幕上打印所有照片文件夹的绝对路径。
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大飞哥软件自习室

希望支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值