Question

How can I get python to return the full pathname of C:\myfolderisafolder\test?

Was it helpful?

Solution

E:\dev>cd VARESE~1

E:\dev\VARESE~1>python
>>> import os
>>> os.getcwd()
'E:\\dev\\VARESE~1'
>>> exit()

E:\dev\VARESE~1>cd ..
E:\dev>cd VAResearchDemo

E:\dev\VAResearchDemo>python
>>> import os
>>> os.getcwd()
'E:\\dev\\VAResearchDemo'
>>> exit()

As you can see, if I run python in VARESE~1 directory, os.getcwd() returns short path. If I run python in same directory but with long path, it returns long path.

So, you should try to run python in C:\myfolderisafolder\test (check link's properties or how you run it).

But if you need to convert a short path to a long path, you have to call win32's GetLongPathName function

OTHER TIPS

Perhaps this would help:

fullpath = os.path.expanduser('~/my/path')

Try to use os.path.realpath, os.path.normpath.

You could just split the string with .split() at the tilde and then rejoin the full filepath with the .join() methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top