Get the correct filepath

BlitzPlus Forums/BlitzPlus Programming/Get the correct filepath

JoshK(Posted 2005) [#1]
How do I get a correct filepath?

"test.txt" and "c:/program files\tEst.txt" both become "C:\Program Files\test.txt".


BlitzSupport(Posted 2005) [#2]
I think you want the full path name with correct case, right? I believe GetFullPathName from kernel32.dll is what you need.


JoshK(Posted 2005) [#3]
GetFullPathName() is the equivalent to CurrentDirectory() plus the file name.


BlitzSupport(Posted 2005) [#4]
Try GetLongPathName.


JoshK(Posted 2005) [#5]
It works! Thanks.


JoshK(Posted 2005) [#6]
You have to convert to a short filename and back.

Function NiceFileName$(file$)
size=Len(file)+100
temp=CreateBank(size)
GetShortPathName(file$,temp,size)
file$=PeekString(temp,0)
GetLongPathName(file$,temp,size)
s$=PeekString(temp,0)
FreeBank temp
Return s
End Function

Notify NiceFileName$("C:\WINDOWS\EXPLORER.EXE")


BlitzSupport(Posted 2005) [#7]
That's a bit weird. You could try passing the original filename to GetLongPathName and if the returned size is less than your buffer size, resize the buffer to the returned size and call again. Then again, if it works, it works...


JoshK(Posted 2005) [#8]
GetLongPathName requires a correct shortpath, so it won't return anything.