4

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

Brad Conyers
  • 811
  • 4
  • 14
  • 21

4 Answers4

5
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

qehgt
  • 2,892
  • 1
  • 20
  • 36
0

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

bluish
  • 23,093
  • 23
  • 110
  • 171
0

Perhaps this would help:

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

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

ihatecache
  • 143
  • 1
  • 9