Advertisement
Guest User

cdJunction.py

a guest
Apr 14th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. ####
  2. ## CD to Junction for Total Commander
  3. ## License: MIT or CC-BY
  4. ## Author: Maciej "Nux" Jaros
  5. ####
  6. import subprocess,sys,os
  7.  
  8. # settings
  9. tcExePath = r'c:\Progs\Totalcmd\TOTALCMD64.EXE'
  10. junctionExePath = r'c:\Progs\Varia\Junction\junction.exe' # TCPROGS - system env. variable
  11.  
  12. # check and set args
  13. dirPath = r'c:\Users\All Users' # test
  14. if len(sys.argv)>=2:
  15.     dirPath = sys.argv[1].rstrip()  # Need to add quotes and space in TC e.g.: "C:\Blah\ "
  16.  
  17. ##
  18. # Get original path of the junction
  19. #
  20. def getOriginalPath(junctionPath):
  21.     cmd = subprocess.Popen(junctionExePath + ' \"' + junctionPath + '\"', shell=True, stdout=subprocess.PIPE)
  22.     for line in cmd.stdout:
  23.         if line.find('Substitute Name:') >= 0:
  24.             start = line.find(':')
  25.             return line[start+1:].strip(" \t\n\\?")+"\\"
  26.             break
  27.     return ""
  28.  
  29. ##
  30. # Change Total Commander current directory
  31. #
  32. def cdTC(newPath):
  33.     subprocess.Popen(tcExePath + ' /O /S /L=\"' + newPath + '\"')
  34.  
  35. #
  36. # Get and CD
  37. #
  38. realPath = getOriginalPath(dirPath)
  39.  
  40. if len(realPath) >= 1:
  41.     cdTC(realPath)
  42. else:
  43.     cdTC(dirPath)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement