Setting win32 console title from Python

runes rune.strand at gmail.com
Thu Apr 28 15:42:34 EDT 2005


Hi Duncan, sorry, I was unprecise.  I'm thinking of a script, called
t.py  that can be used in the console  like an ordinary command. Som if
I change directory from S:\scripts to d:\projects and execute the
script  the title changes to "projects" etc.

I have that functionality today with a combination of a python script
and a batch file. I just wondered if I could use python all the way.
Apparently I cannot.

Here are the scripts:


------ DirInPath:\t.bat --------------------------------
@echo off
:: reads bare directory name from file
:: created by external Python script
set DIR_FILE_NAME=DOS_IS_TERRIBLE.tmp
PyBareDir.py %DIR_FILE_NAME%

for /F "eol=;" %%t in (%DIR_FILE_NAME%) do (
	title %%t
)

del /Q /F DOS_IS_TERRIBLE.tmp
------------------------------------------------------------


------ DirInPath:\PyBareDir.py --------------------------------
# extracts bare directory name and  writes
# it to file with name given as argument.

from os import getcwd
from os.path import basename
import sys

try:
	saveAsName = sys.argv[1]
	lastDir = basename(getcwd())
	XWwz(saveAsName, 'w+').write(lastDir + '\n;')
except:
	print "PyBareDir failed:", sys.exc_info()[1]

-----------------------------------------------------------------------




More information about the Python-list mailing list