Simple to learn a few days of Python, always feel the best according to their own needs to do some small tools to combat.
There are many directories that need to be opened when you go to work. Every time you have to look for those directories.
I think I need a gadget. Then register all the directories that need to be opened. Then you can easily open all the directories in one click.
Or what files are available. Then register. All registered targets can be opened at once
Each time you open the tool, you need to read the XML data. Each additional piece of data is written to the XML.
This allows us to add records even if the department uses assistive tools. It is also possible to modify the data of the XML file directly to increase the record.
The specific implementation is as follows
Import Osimport Xml.dom.minidom as xmldomdatas={}savepath= "./manager.xml" Def Main (): LoadXml (Savepath) while (True): Print ("Directory Shortcut Manager") result= input ("1, display directory data 2, add new management directory 3, clear screen 4, start management 0, open all directories:") if result== "1": For key in Datas.keys (): Print (Key,datas[key]) elif result== "2": Os.system ("CLS") AddData () elif result = = "3": Os.system ("CLS") elif result = = "4": Os.system ("C LS ") Manager () elif result = =" 0 ": OpenAll () Os.system (" CLS ") Else: Print ("Input error please re-enter.") #从文件中load数据到内存def loadXml (Xmlpath): root= xmldom.parse (Xmlpath) Nodes=root.getelementsbytagname ("Node") print ("All Directory list: ") for node in Nodes:key=node.getattribute (" name ") Value=node.getattribute (" path ") Datas[key ]=value print (Key,value) #保存内存数据到文件def savexml (Xmlpath): Root=xmldom. Document () nodes= root.createelement ("PathData ") Root.appendchild (nodes) for key in Datas:node=root.createelement (" Node ") Node.setattribute (" NA Me ", key) Node.setattribute (" path ", Datas[key]) nodes.appendchild (node) with open (Xmlpath," wb+ ") as File: Savestr=root.toprettyxml (indent= ' t ', encoding= "Utf-8") print (SAVESTR) file.write (SAVESTR) #打开所有保存的目录def OpenAll (): for key in datas:data = Datas[key] If os.path.exists (data): Os.startfile (Datas[ke Y]) print (key, "boot Success") Else:print (Key, "not present, failed to start.") #添加新的路径模块def AddData (): while (True): key = input ("Please enter a nickname (Input Q exit):") if key.lower () = = ' Q ': Brea K Value = input ("Please enter full path:") if Os.path.exists (value): datas[key] = value SaveXML (savepath) Print ("Add path failed, path does not exist") #启动管理的模块def Manager (): Print ("Alias list:") for key in Datas.keys (): Print (key) Whil E true:startname = input ("Enter the startup nickname (all start all, Q exit toPrevious layer): ") if startname.lower () = = ' Q ': break; If startname.lower () = = ' All ': OpenAll () Continue data = Datas.get (startname) if data: If Os.path.exists (data): Os.startfile (data) print ("Open successfully", StartName) Els E:print (data, "path does not exist.") If __name__== "__main__": Main ()
Python combat: A directory One-click launch Management Gadget