Python搜索文件代码,,这里以在windows下
Python搜索文件代码,,这里以在windows下
这里以在windows下搜索并启动QQ为例,我先把开始菜单、桌面和快速启动栏找了一遍,这样能缩短查找时间。如果找不到再到每个分区中查找。 python import os disk=['D','E','F','G','H'] def search_file(filename,search_path,pathsep=os.pathsep): for path in search_path.split(pathsep): candidate = os.path.join(path,filename) if os.path.isfile(candidate): return os.path.abspath(candidate) if __name__=='__main__': found=False for i in os.walk('C:\ProgramData\Microsoft\Windows\Start Menu\Programs'): search_path=i[0] find_file=search_file('腾讯QQ.lnk',search_path) if find_file: os.startfile(find_file) found=True if not found: for i in os.walk('C:\Users\Jack\Desktop'): search_path=i[0] find_file=search_file('QQ.exe.lnk',search_path) if find_file: os.startfile(find_file) found=True if not found: for i in os.walk('C:\Users\Jack\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch'): search_path=i[0] find_file=search_file('腾讯QQ.lnk',search_path) if find_file: os.startfile(find_file) found=True if not found: for i in range(0,5): for j in os.walk(disk[i]+':/'): search_path=j[0] find_file=search_file('QQProtect.exe',search_path) if find_file: os.startfile(find_file) found=True if not found: for i in os.walk('C:/Program Files/QQ'): search_path=i[0] find_file=search_file('QQProtect.exe',search_path) if find_file: os.startfile(find_file) found=True if not found: print"无法找到QQ"
相关内容
- Python计算-质数的判断,python计算质数,#!/usr/bin/p
- python实现数据结构中的栈,python实现数据结构,#coding:
- RedDog文字式猜点数游戏,reddog文字点数,运行结果-----
- python多父类继承示例,python继承示例,class A:
- 去掉当前目录下电影名字前的框框,当前目录框框,#!
- 抓取淘宝下拉框关键词,抓取下拉框关键词,import urll
- python遍历目录树代码,python历目录树,from os.path
- python登录pop3邮件服务器接收邮件,pythonpop3,import popli
- python统计文本字符串里面单词出现的频率,python字符串
- python爬虫-爬取代理IP并通过多线程快速验证,python爬虫
评论关闭