[python-win32] cwd of program

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Oct 21 15:42:40 CEST 2005


[le dahut]

> I try to get the program's directory, the one where the .exe (or .py)
is.

From within Python, sys.argv[0] usually gives you the running
program (not sure what it does with py2exe etc.). So something
like (untested):

<code>
import os, sys

print os.path.dirname (sys.argv[0])

</code>

> With os.getcwd() I get the directory from where the program is
launched 
> not his directory. The program has to copy some files and thus I get
an 
> error like "XXXXXX no such file or directory".

Umm. It's not clear why you get "no such file / directory". Surely
os.getcwd returns *some* real directory. Or is it that you don't
have permissions to the directory?

> (the DOS box closed to quickly to have the detailed 
> error msg...) where XXXXXX is a sub-directory of 
> the program's one.

I'm assuming you're double-clicking on a Python icon to
run the program. You might try, instead, running it from
the command line: 

Start > Run > cmd.exe
(DOS box opens)
python x:\path\to\my\program.py

This should let you see what's going on.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list