Get the correct filepath

BlitzPlus Forums/BlitzPlus Programming/Get the correct filepath

How do I get a correct filepath?

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

I think you want the full path name with correct case, right? I believe GetFullPathName from kernel32.dll is what you need.

GetFullPathName() is the equivalent to CurrentDirectory() plus the file name.

Try GetLongPathName.

It works! Thanks.

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")

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...

GetLongPathName requires a correct shortpath, so it won't return anything.