loadPrcFile problem [SOLVED]

Hi, i can’t manage to load a copy of the Config.prc file located in the root folder of my application under windows.

if i do this:

from pandac.PandaModules import loadPrcFile
loadPrcFile("Config.prc")
import direct.directbase.DirectStart
print cpMgr
run()

the program shows that the loaded files are the panda3d/etc ones

and, if do this:

import sys, os.path
from pandac.PandaModules import loadPrcFile
rootDir = os.path.abspath(os.path.dirname(sys.argv[0]))
loadPrcFile(os.path.join(rootDir, "Config.prc"))
import direct.directbase.DirectStart
print cpMgr
run()

the program traces the message:

Unable to open C:Users\Snaptothegrid\Desktop\app\Config.prc

of course, the file is located in this path exactly, i’m so shure about this.

I am missing something? Doing something wrong?
Thanks.

if this is precisely the error report looks like you got the double bars ‘\’ preceding C: eaten up for some reason. Can’t say why though…
just try to double the double bars here sys.argv[0] with a replace() and see if works
PS: we peek us up later on pm

ops, sorry, the exact error is:

Unable to open C:\Users\Snaptothegrid\Desktop\app\Config.prc

i’ts really weird, looks like it should work but don’t.

ok, if i set rootDir manualy to

rootDir="/c/Users/Snaptothegrid/Desktop/app"

it works.
Now i have to find a way to convert de path returned by sys to this format…
Thanks, your tip has been of great help!

Try this:

rootDir=Filename.fromOsSpecific("C:\\Blah\\Dir\\ABC").getFullpath()

forgot to say: have you tried the os.getcwd()?
what does return back?
anyhow don’t ever use the sys.argv just to snatch the current path cos, as you saw, is not reliable
when building paths I use to go like this:

root=os.getcwd()
subpath=os.path.join(root, whatever_subfolder_path_under_the_root)

Perfect guys!
the key here is the filename panda thing to convert to this kind of

/c/whatever/panda3dpathformat

also thanks for this new manner of getting the path.

combining this last two post is the perfect solution :slight_smile:
Thanks!

Note that ExecutionEnvironment.getCwd() directly returns the current working directory in os-independent form.