要点:使用系统模块,遍历磁盘,遍历文件,找到符合条件的文件记录下来到一个Log文件中(XML格式).
python 代码
 
  1. import win32api  
  2. import os  
  3.   
  4. #constants and configs  
  5. IGNORE_PATH = [  
  6.     "C:\\WINDOWS",  
  7.     "C:\\Program Files",  
  8.     "C:\\Documents and Settings",  
  9.     "C:\\System Volume Information"  
  10.     ]  
  11.   
  12. #TODO use re replace  
  13. IMAGE_TYPE = [  
  14.     "jpg","gif","png","jpeg","bmp"  
  15.     ]  
  16. #find out the logic disks  
  17.   
  18. disks = win32api.GetLogicalDriveStrings().split("\x00")  
  19. for disk in disks:  
  20.     if disk in ['','A:\\']:  
  21.         disks.remove(disk)  
  22.          
  23. #TODO store to xml file  
  24. def store(filePath,fileName):  
  25.     print 'about to store %s\\%s' % (filePath,fileName)  
  26.   
  27. def scan(path):  
  28.     print 'scanding path : ' + path  
  29.     if not path.endswith('\\'):  
  30.         path = path + '\\'  
  31.     for _file in os.listdir(path):  
  32.         if os.path.isdir(path + _file) and path + _file not in IGNORE_PATH:  
  33.             scan(path + _file)  
  34.         else:  
  35.             for image_type in IMAGE_TYPE:  
  36.                 if _file.endswith(".%s" % image_type):  
  37.                     store(path,_file)  
  38.                     break  
  39.      
  40. # now iterat the disks  
  41. for disk in disks:  
  42.     print 'now scan disk : %s ' % disk  
  43.     scan(disk)  

到此为止,Python把硬盘里的图片都找出来了,还差把图片信息存储到XML文件里面去.
TODOs:
一,使用正则表达式匹配后缀名
二,保存信息到XML           
评论
发表评论

您还没有登录,请登录后发表评论

我想我是海
搜索本博客
存档
最新评论