最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

Python实现查找系统盘中需要找的字符

来源:动视网 责编:小采 时间:2020-11-27 14:34:27
文档

Python实现查找系统盘中需要找的字符

Python实现查找系统盘中需要找的字符:本文实例讲述了Python实现查找系统盘中需要找的字符。分享给大家供大家参考。具体如下: ''' Created on 2011-7-13 @author: 123 ''' import os #保存当前有的磁盘 def existdisk(): curdisks = [] allDisks = ['C:',
推荐度:
导读Python实现查找系统盘中需要找的字符:本文实例讲述了Python实现查找系统盘中需要找的字符。分享给大家供大家参考。具体如下: ''' Created on 2011-7-13 @author: 123 ''' import os #保存当前有的磁盘 def existdisk(): curdisks = [] allDisks = ['C:',


本文实例讲述了Python实现查找系统盘中需要找的字符。分享给大家供大家参考。具体如下:

'''
Created on 2011-7-13
@author: 123
'''
import os
#保存当前有的磁盘
def existdisk():
 curdisks = []
 allDisks = ['C:', 'D:', 'E:', 'F:', 'G:', 'H:', 'I:', 'J:', 'K:', 
 'L:', 'M:', 'N:', 'O:', 'P:', 'Q:', 'R:', 'S:', 'T:', 
 'U:', 'V:', 'W:', 'X:', 'Y:', 'Z:', 'A:', 'B:']
 for disk in allDisks:
 if os.path.exists(disk):
 curdisks.append(disk)
 return curdisks
#目录中含有查找的字符
def SearchDirFile(path, src):
 if not os.path.exists(path):
 print "%s 路径不存在" % path
 for root , dirs, files in os.walk(path, True):
 if - 1 != root.find(src):
 #路径名中是否存在要查找的字符
 print root 
 for item in files:
 path = os.path.join(root, item)
 if - 1 != path.find(src):
 #文件列表中是否有要查找的字符
 print path
#查找文件内容中有要查找的字符
def SearchFile(path, src): 
 if not os.path.exists(path):
 print "%s 路径不存在" % path
 for root, dirs, files in os.walk(path, True):
 for item in files:
 path = os.path.join(root, item)
 try:
 f = open(path, 'r')
 for eachline in f.readlines():
 if - 1 != eachline.find(src):
 #文本内容中是否有要查找的字符
 print path
 f.close()
 break
 except:
 pass
#查找当前所有磁盘目录下是否有要找的字符
def SearchAllDirFile(src): 
 curdisks = existdisk()
 for disk in curdisks:
 disk = disk + '\'
 SearchDirFile(disk, src)
 print "完成搜索"
#查找当前所有磁盘目录文件内容下是否有要找的字符
def SearchALLFile(src): 
 curdisks = existdisk()
 for disk in curdisks:
 disk = disk + "\"
 SearchFile(disk, src)
 print "完成搜索"
SearchALLFile('十进制转二进制')

希望本文所述对大家的Python程序设计有所帮助。

文档

Python实现查找系统盘中需要找的字符

Python实现查找系统盘中需要找的字符:本文实例讲述了Python实现查找系统盘中需要找的字符。分享给大家供大家参考。具体如下: ''' Created on 2011-7-13 @author: 123 ''' import os #保存当前有的磁盘 def existdisk(): curdisks = [] allDisks = ['C:',
推荐度:
标签: 查找 系统盘 字符
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top