- 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"
来源: http://www.phpxs.com/code/1004939/