• 快速切换目录工具c之windows版本


    1. #!/usr/bin/env python
    2. import os,sys
    3. #import fcntl,termios
    4. import winput
    5. from winput.vk_codes import *
    6. dirlstfile = "\\bin\\.dirlst"
    7. dirlst = open(dirlstfile, "r+").read().split("\n")[:-1]
    8. updated = 0
    9. def listdir(dirlst, filter):
    10. startc = 'a'
    11. lastc = 'a'
    12. dircnt = 0
    13. for item in dirlst:
    14. if item!='' and filter in item:
    15. print(startc,item)
    16. lastc = startc
    17. dircnt+=1
    18. startc=chr(ord(startc)+1)
    19. if dircnt == 0 :
    20. print("use 'c +' to add dir cache")
    21. return
    22. if dircnt == 1:
    23. seldir(dirlst, lastc)
    24. return
    25. ret = input("select:")
    26. if ret == '':return
    27. seldir(dirlst, ret[0])
    28. def shellcmd(cmd):
    29. #for c in cmd:fcntl.ioctl(0, termios.TIOCSTI,c)
    30. for c in cmd:
    31. val = ord(c)
    32. if c==':':
    33. winput.press_key(VK_SHIFT)
    34. winput.click_key(0xBA)
    35. winput.release_key(VK_SHIFT)
    36. continue
    37. if c=='\\':
    38. winput.click_key(0xE2)
    39. continue
    40. if val==0x0a:
    41. winput.click_key(0x0D)
    42. continue
    43. if c=='/':
    44. winput.click_key(0xBF)
    45. continue
    46. if c=='.':
    47. winput.click_key(0xBE)
    48. continue
    49. if val>= 0x40 and val<0x60:
    50. winput.press_key(VK_SHIFT)
    51. winput.click_key(val)
    52. winput.release_key(VK_SHIFT)
    53. continue
    54. if val>= 0x60 and val<0x80:
    55. val &= ~0x20
    56. winput.click_key(val)
    57. winput.stop()
    58. def seldir(dirlst, c):
    59. #print("cd %s\n"%(dirlst[ord(c)-ord('a')]))
    60. shellcmd("cd %s\n"%(dirlst[ord(c)-ord('a')]))
    61. if len(sys.argv) > 1:
    62. if sys.argv[1] == '-':
    63. updated = 1
    64. if len(sys.argv) == 2:
    65. if os.getcwd() in dirlst:
    66. print("remove self")
    67. dirlst.remove(os.getcwd())
    68. else:
    69. startc = 'a'
    70. dirbak = dirlst.copy()
    71. for item in dirlst:
    72. if startc in sys.argv[2]: dirbak.remove(item)
    73. startc=chr(ord(startc)+1)
    74. dirlst = dirbak.copy()
    75. elif sys.argv[1] == '+':
    76. if os.getcwd() not in dirlst:
    77. dirlst.append(os.getcwd())
    78. for item in dirlst:
    79. if item=="":
    80. item=os.getcwd()
    81. dirlst=dirlst[:-1]
    82. break
    83. updated = 1
    84. elif '1' <= sys.argv[1][0] <= '9' and len(sys.argv[1]) == 1:
    85. shellcmd("cd %s\n"%('../'*(ord(sys.argv[1])-ord('0'))))
    86. elif len(sys.argv[1]) == 1:
    87. seldir(dirlst, sys.argv[1])
    88. else:
    89. listdir(dirlst, sys.argv[1])
    90. else:
    91. listdir(dirlst, "")
    92. if updated == 1:
    93. fl = open(dirlstfile, "w")
    94. for item in dirlst:
    95. fl.write("%s\n"%item)

    效果截图,切换任意目录,只需要一行3~4个字符的按键命令。

  • 相关阅读:
    (总目录)springboot - 实现zip文件上传并对zip文件解压, 包含上传oss
    热乎的过万字GameFramework讲解笔记文档
    node封装一个控制台进度条插件
    [做初中数学题做到打起来了]跟同事为了他小孩的数学题杠上了
    uniapp微信小程序半屏跳转小程序
    mysql之行锁和表锁篇
    知识点17:关闭MMU时,cache的缓存策略是怎样的?
    1.python简介
    #include<>和#include“”的区别
    安装oem 13c
  • 原文地址:https://blog.csdn.net/lzf_china/article/details/139251969