可以給Windows電腦中文件夾設(shè)置備注的小工具

[重要通告]如您遇疑難雜癥,本站支持知識付費(fèi)業(yè)務(wù),掃右邊二維碼加博主微信,可節(jié)省您寶貴時(shí)間哦!

前段時(shí)間有一朋友問如何給文件夾做備注,問的一臉懵逼,也確實(shí)沒有遇到過此文件,直到有一天,遇到這個(gè)小工具,還真不錯(cuò);

通過該工具可以給Windows電腦中文件夾設(shè)置備注;

代碼如下:

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='校驗(yàn)/保存', 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('不存在,準(zhǔn)備創(chuàng)建')
      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

    # 創(chuàng)建管理對象
    conf = configparser.ConfigParser()
    # 讀ini文件
    conf.read(dirPath+'/desktop.ini', encoding="GBK")
    # 獲取所有的section
    sections = conf.sections()
    print(sections)

    # 添加一個(gè)select
    conf.add_section(".ShellClassInfo")
    conf.set(".ShellClassInfo", "IconResource",
            "C:\WINDOWS\System32\SHELL32.dll,4")
    conf.set(".ShellClassInfo", "InfoTip", '"'+InfoTip+'"')
    print(conf.sections())

    # 添加一個(gè)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"))  # 追加模式寫入
    # 關(guān)閉文件
    file.close()

    # 設(shè)置權(quán)限 
    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, '備注設(shè)置完成,退出本程序后生效', '提示', 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('不存在,準(zhǔn)備創(chuàng)建')
    file = open(dirPath+'/desktop.ini', 'w')
    file.close()
  else:
    print('已存在,是否刪除(Y/N)?')
    isDel = input()
    # 不區(qū)分大小寫判斷
    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()

  # 創(chuàng)建管理對象
  conf = configparser.ConfigParser()
  # 讀ini文件
  conf.read(dirPath+'/desktop.ini', encoding="GBK")
  # 獲取所有的section
  sections = conf.sections()
  print(sections)

  # 添加一個(gè)select
  conf.add_section(".ShellClassInfo")
  conf.set(".ShellClassInfo", "IconResource",
          "C:\WINDOWS\System32\SHELL32.dll,4")
  conf.set(".ShellClassInfo", "InfoTip", '"'+InfoTip+'"')
  print(conf.sections())

  # 添加一個(gè)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"))  # 追加模式寫入
  # 關(guān)閉文件
  file.close()

  # 設(shè)置權(quán)限
  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__':
  # 默認(rèn)執(zhí)行age_c 當(dāng)接收到u時(shí)執(zhí)行age_u
  if '-c' in sys.argv:
    age_c()
  else:
    age_u()

打包exe,在這里:下載:https://wwi.lanzoup.com/ie5il0insh1i? ?密碼 (好孩子看不見):? 52pj

項(xiàng)目地址:https://github.com/dengsuchuan/WinDirRemarksTools

問題未解決?付費(fèi)解決問題加Q或微信 2589053300 (即Q號又微信號)右上方掃一掃可加博主微信

所寫所說,是心之所感,思之所悟,行之所得;文當(dāng)無敷衍,落筆求簡潔。 以所舍,求所獲;有所依,方所成!

支付寶贊助
微信贊助

免責(zé)聲明,若由于商用引起版權(quán)糾紛,一切責(zé)任均由使用者承擔(dān)。

您必須遵守我們的協(xié)議,如您下載該資源,行為將被視為對《免責(zé)聲明》全部內(nèi)容的認(rèn)可->聯(lián)系老梁投訴資源
LaoLiang.Net部分資源來自互聯(lián)網(wǎng)收集,僅供用于學(xué)習(xí)和交流,請勿用于商業(yè)用途。如有侵權(quán)、不妥之處,請聯(lián)系站長并出示版權(quán)證明以便刪除。 敬請諒解! 侵權(quán)刪帖/違法舉報(bào)/投稿等事物聯(lián)系郵箱:service@laoliang.net
意在交流學(xué)習(xí),歡迎贊賞評論,如有謬誤,請聯(lián)系指正;轉(zhuǎn)載請注明出處: » 可以給Windows電腦中文件夾設(shè)置備注的小工具

發(fā)表回復(fù)

本站承接,網(wǎng)站推廣(SEM,SEO);軟件安裝與調(diào)試;服務(wù)器或網(wǎng)絡(luò)推薦及配置;APP開發(fā)與維護(hù);網(wǎng)站開發(fā)修改及維護(hù); 各財(cái)務(wù)軟件安裝調(diào)試及注冊服務(wù)(金蝶,用友,管家婆,速達(dá),星宇等);同時(shí)也有客戶管理系統(tǒng),人力資源,超市POS,醫(yī)藥管理等;

立即查看 了解詳情