Today is the first day to write a blog. I don't know what to write. I'll write a small program first. If you need to modify it, please give me more advice!
Everyone envies the high salary of programmers, but they don't know the hardships behind it. It can be thought that programmers are making money with their lives, working overtime every day to knock on the code, only to fix the bug s in the program and make their program more perfect. Why are they so good? The reason lies in their love and persistence. It's easy to do one thing, but it's difficult to insist on doing one thing all the time. Every programmer is growing up from a line of code, learning and applying these knowledge every day, and slowly finding that they can also be very good. It's not very difficult to do a thing. What's difficult is that you dare not start to do it. It's not so difficult after you really touch it. Nothing is born, it's all accumulated bit by bit, so I'll stick to writing something from today, no matter how others think I'm happy, I'll stick to it!
To modify the applet of the hosts file:
1 import os 2 import collections 3 4 def getAllDirQueue(path): 5 queue = collections.deque() 6 queue.append(path) 7 while len(queue) != 0: 8 dirPath = queue.popleft() 9 fileList = os.listdir(dirPath) # Find out all the files saved in the list 10 for fileName in fileList: 11 fileAbsPath = os.path.join(dirPath, fileName) 12 if os.path.isdir(fileAbsPath): # Judge whether it's a directory. If it's a directory, enter the team 13 queue.append(fileAbsPath) 14 else: 15 if fileName == 'hosts': 16 print('Warm tip: Please input information insert,Exit please enter exit!') 17 Tips = input('Please enter what you want to do:') 18 if Tips == 'insert': 19 while True: 20 info = input('Please enter the information you want to add:') # For example: 127.0.0.1 www.cnblogs.com 21 if info != 'exit': 22 with open(fileAbsPath, 'a') as f: 23 f.write(info + '\n') 24 else: 25 print('I wish you all the best!') 26 break 27 elif Tips == 'exit': 28 print('I wish you all the best!') 29 30 getAllDirQueue(r"C:\Windows\System32\drivers\etc")