可以给Windows电脑中文件夹设置备注的小工具
[重要通告]如您遇疑难杂症,本站支持知识付费业务,扫右边二维码加博主微信,可节省您宝贵时间哦!
前段时间有一朋友问如何给文件夹做备注,问的一脸懵逼,也确实没有遇到过此文件,直到有一天,遇到这个小工具,还真不错;
通过该工具可以给Windows电脑中文件夹设置备注;
代码如下:
import wx
import os
import time
import sys
import configparser
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='文件夹备注工具', size=(
505, 139), name='frame', style=541072384)
self.runW = wx.Panel(self)
self.Centre()
self.editB0x1 = wx.TextCtrl(self.runW, size=(291, 31), pos=(
82, 10), value='', name='text', style=0)
self.editB0x1.Bind(wx.EVT_LEFT_DOWN, self.editB0x1_mLeftC)
self.leb1 = wx.StaticText(self.runW, size=(61, 18), pos=(
11, 19), label='文件夹路径', name='staticText', style=2321)
self.leb2 = wx.StaticText(self.runW, size=(61, 20), pos=(
12, 60), label='备注', name='staticText', style=2321)
self.editB0x2 = wx.TextCtrl(self.runW, size=(291, 31), pos=(
82, 53), value='', name='text', style=0)
self.button2 = wx.Button(self.runW, size=(91, 70), pos=(
389, 14), label='校验/保存', name='button')
button2_font = wx.Font(12, 74, 90, 700, False, 'Microsoft YaHei UI', 28)
self.button2.SetFont(button2_font)
self.button2.Bind(wx.EVT_LEFT_DOWN, self.button2_mLeftC)
def editB0x1_mLeftC(self,event):
print('editB0x1,mLeftC')
# 选择文件夹
dlg = wx.DirDialog(self, "选择文件夹", style=wx.DD_DEFAULT_STYLE)
if dlg.ShowModal() == wx.ID_OK:
self.editB0x1.SetValue(dlg.GetPath())
dlg.Destroy()
def button2_mLeftC(self,event):
print('button2,mLeftC')
# 判断路径是否存在
if not os.path.exists(self.editB0x1.GetValue()):
print('路径不存在')
dlg = wx.MessageDialog(self, '路径不存在', '提示', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
return False
if not self.editB0x2.GetValue():
print('备注不能为空')
dlg = wx.MessageDialog(self, '备注不能为空', '提示', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
return False
dirPath = self.editB0x1.GetValue()
InfoTip = self.editB0x2.GetValue()
if os.path.exists(dirPath+'/desktop.ini') == False:
print('不存在,准备创建')
file = open(dirPath+'/desktop.ini', 'w')
file.close()
else:
# 弹框询问
dlg = wx.MessageDialog(self, '是否覆盖原有备注', '提示', wx.YES_NO | wx.ICON_INFORMATION)
if dlg.ShowModal() == wx.ID_YES:
# 先删除文件
os.system('attrib '+dirPath+'/desktop.ini -r -h')
time.sleep(0.05)
os.remove(dirPath+'/desktop.ini')
file = open(dirPath+'/desktop.ini', 'w')
file.close()
else:
print('不覆盖')
return False
# 创建管理对象
conf = configparser.ConfigParser()
# 读ini文件
conf.read(dirPath+'/desktop.ini', encoding="GBK")
# 获取所有的section
sections = conf.sections()
print(sections)
# 添加一个select
conf.add_section(".ShellClassInfo")
conf.set(".ShellClassInfo", "IconResource",
"C:\WINDOWS\System32\SHELL32.dll,4")
conf.set(".ShellClassInfo", "InfoTip", '"'+InfoTip+'"')
print(conf.sections())
# 添加一个select
conf.add_section("ViewState")
conf.set("ViewState", "Mode", "")
conf.set("ViewState", "Vid", "")
conf.set("ViewState", "FolderType", "Generic")
print(conf.sections())
conf.write(open(dirPath+'/desktop.ini', "a")) # 追加模式写入
# 关闭文件
file.close()
# 设置权限
os.system('attrib '+dirPath+'/desktop.ini +r +h')
time.sleep(0.05)
# 刷新
os.system('attrib '+dirPath+' +s /d')
time.sleep(0.05)
dlg = wx.MessageDialog(self, '备注设置完成,退出本程序后生效', '提示', wx.OK | wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
class myApp(wx.App):
def OnInit(self):
self.frame = Frame()
self.frame.Show(True)
return True
def age_c():
print('命令行模式')
print('文件夹路径:')
dirPath = input()
# 判断路径是否存在
if not os.path.exists(dirPath):
print('路径不存在')
exit()
# 路径下是否存在'./desktop.ini'文件
if os.path.exists(dirPath+'/desktop.ini') == False:
print('不存在,准备创建')
file = open(dirPath+'/desktop.ini', 'w')
file.close()
else:
print('已存在,是否删除(Y/N)?')
isDel = input()
# 不区分大小写判断
if isDel.upper() == 'Y':
# 先删除文件
os.system('attrib '+dirPath+'/desktop.ini -r -h')
time.sleep(0.05)
os.remove(dirPath+'/desktop.ini')
file = open(dirPath+'/desktop.ini', 'w')
file.close()
else:
exit()
print('路径备注:')
InfoTip = input()
# 创建管理对象
conf = configparser.ConfigParser()
# 读ini文件
conf.read(dirPath+'/desktop.ini', encoding="GBK")
# 获取所有的section
sections = conf.sections()
print(sections)
# 添加一个select
conf.add_section(".ShellClassInfo")
conf.set(".ShellClassInfo", "IconResource",
"C:\WINDOWS\System32\SHELL32.dll,4")
conf.set(".ShellClassInfo", "InfoTip", '"'+InfoTip+'"')
print(conf.sections())
# 添加一个select
conf.add_section("ViewState")
conf.set("ViewState", "Mode", "")
conf.set("ViewState", "Vid", "")
conf.set("ViewState", "FolderType", "Generic")
print(conf.sections())
conf.write(open(dirPath+'/desktop.ini', "a")) # 追加模式写入
# 关闭文件
file.close()
# 设置权限
os.system('attrib '+dirPath+'/desktop.ini +r +h')
time.sleep(0.05)
# 刷新
os.system('attrib '+dirPath+' +s /d')
time.sleep(0.05)
def age_u():
print('GUI模式')
app = myApp()
app.MainLoop()
if __name__ == '__main__':
# 默认执行age_c 当接收到u时执行age_u
if '-c' in sys.argv:
age_c()
else:
age_u()
打包exe,在这里:下载:https://wwi.lanzoup.com/ie5il0insh1i 密码 (好孩子看不见): 52pj
项目地址:https://github.com/dengsuchuan/WinDirRemarksTools
问题未解决?付费解决问题加Q或微信 2589053300 (即Q号又微信号)右上方扫一扫可加博主微信
所写所说,是心之所感,思之所悟,行之所得;文当无敷衍,落笔求简洁。 以所舍,求所获;有所依,方所成!
赏
支付宝赞助
微信赞助
支付宝赞助
微信赞助免责声明,若由于商用引起版权纠纷,一切责任均由使用者承担。
您必须遵守我们的协议,如您下载该资源,行为将被视为对《免责声明》全部内容的认可->联系老梁投诉资源 LaoLiang.Net部分资源来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。
敬请谅解! 侵权删帖/违法举报/投稿等事务联系邮箱:service@laoliang.net
意在交流学习,欢迎赞赏评论,如有谬误,请联系指正;转载请注明出处: » 可以给Windows电脑中文件夹设置备注的小工具


