I'm looking for a way to write a few batch scripts to use as custom shell commands using python.
Here's a simple example:
FILENAME: gotofile.bat (put this batch commands file somewhere visible from %PATH%)
@setlocal enableextensions & "C:/Python27/python.exe" -x "%~f0" %* & goto :EOF
# Looks for a file on disk and take me there
import sys
import os
if len(sys.argv) == 2:
for root, dirnames, filenames in os.walk(os.getcwd()):
for filename in filenames:
if filename == sys.argv[1]:
print 'TAKING YOU TO: %s'%root
os.system('cls')
os.system('title %s'%root)
os.system('cd %s'%root)
quit()
Now from a cmd shell type gotofile some_file_you_wish_to_find.ext (pick a file that is not too far away, or else os.walk
will take a while)
Assuming it exists, Python should find your file, print where it would like to take you, the cls os.system call will correctly clear your screen but the two other os.system
calls don't do anything.
Is there any way of making this work? Or will I have to do this all natively in batch?