Python combat: A directory One-click launch Management Gadget

Source: Internet
Author: User
Tags clear screen

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.