# -*- encoding: utf-8 -*-from os import makedirs, chdir, listdir, popenfrom os.path import exists, join, basename# 功能:命令行+启动器# 显示已有的exe列表,# 可以添加EXE路径# 可以删除EXE路径文件# 在命令行启动exe文件# os.popen("start E:\小工具\查找水浒108好汉信息.exe")class Exe:def __init__(self):passdef os_path(self):## 信息存放处,运行过后目录切换到f:\\exe启动器info\\path = "d:\\exe启动器info"ifexists = exists(path)if ifexists is not True:makedirs(path)chdir(path)else:chdir(path)def read(self): # 读取当前目录,列出当前目录的文件file = listdir('.')for i, j in enumerate(file, start=1):print(i, j, end=' ')print()def open(self, flag): # 选择需要运行的程序filename = input("请输入选择的序号:")lst = list()file = listdir('.')for i, j in enumerate(file, start=1):st = str(i) + '*'+ jlst.append(st)for i in lst:if filename + '*' in i:i = i.replace(filename + '*', '')if flag == '1':Exe.os_read(self, i) # 运行else:Exe.os_rm(self, i) # 删除def echo(self,flag): # 选择需要运行的程序print("-*"*30, "\n", "信息存储目录已加载,echo命令"+flag, sep='-')def os_write(self): # 添加EXE文件的路径,文件名,启动文件写入filepath1 = input('【例:E:\小工具\查找水浒108好汉信息.exe】\n请先输入文件路径:')filepath2 = input('请输入文件名:')filepath = join(filepath1, filepath2) # 合并文件路径和文件名filename = basename(filepath).replace('.exe', '') # 文件的名字shell = 'start ' + filepathwith open(filename + '.txt', 'w', encoding='utf-8') as f:f.write(shell)f.close()def os_read(self, file): # 读取文件内容并在命令行中运行with open(file, 'r', encoding='utf-8') as f:h = f.read()p = popen(h).read()print(p, "-*- 文件正在启动 -*-\n请稍等片刻", end='')f.close()def os_rm(self, filename): # 删除文件shell = 'del ' + str(filename)popen(shell)if __name__ == '__main__':e = Exe()e.os_path()print("-*"*30, "\n", "信息存储目录已加载,默认存放目录 f:\\exe启动器info\\\n", sep='-')e.read() # 读取文件列表while True:cmd = input('')if cmd.lower() == 'list': # 运行e.echo('1') # 运行的方法breakelif cmd == '2': # 添加e.os_write() # 写入的方法print('-*'*30, sep='-')e.read()print()else: # 删除e.open('2') # 删除的方法print('-*'*30, sep='-')e.read() # 读取列表print()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。