How can I get python to return the full pathname of C:\myfolderisafolder\test?
Asked
Active
Viewed 993 times
4 Answers
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
Alexander A.Sosnovskiy
- 787
- 7
- 16
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