Get EXE (made with py2exe) path directory name

A

Andrei B

I need to get absolute path name of a file that's in the same dir as
the exe, however the Current Working Directory is changed to somthing
else.

I turn my script into an executable with py2exe, then I create a
shortcut to the EXE on the desktop. I change the "Start In" variable of
the shortcut "C:\somthing_else", so now the currect working directory
of the executable is not the same as the directory where the EXE is
located.

I need to load a file that's in the same directory as the EXE, so I do
the following:

dir = os.path.dirname(sys.argv[0])
filepath = os.path.join(dir, 'server.pkey')

however it doesn't seem to work.

Any idea?

thanks!
 
J

Justin Ezequiel

try,

if hasattr(sys, 'frozen'): me = sys.executable
else: me = sys.argv[0]
 
S

Serge Orlov

Andrei said:
I need to get absolute path name of a file that's in the same dir as
the exe, however the Current Working Directory is changed to somthing
else.

Use sys.path[0]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top