~1 paths
BlitzMax Forums/BlitzMax Programming/~1 paths
| ||
For some reason, blitzmax doesn't like paths with ~1 in them: "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ssftmp\" Is there a way to convert the path to its full name? |
| ||
~ is the escape character in BlitzMax. Use ~~ to represent ~. |
| ||
I'm getting these strings at runtime not at compile time, and they are different depending on user, blitzmax only replaces escape chars at compile time. EDIT: example: Global temp_dir:String = getenv_("temp") DebugLog temp_dir' on my computer i receive "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp" |
| ||
Here's what I have so far.. but it doesn't work.DebugLog GetFullPath(getenv_("temp")) Function GetFullPath:String(shortpath:String) Local lngpath:Byte Ptr, size:Int = Len(shortpath) GetLongPathNameW(shortpath, lngpath, 1024) Return String.fromcstring(lngpath) End Function Extern "win32" Function GetLongPathNameW(lpzshortpath:String, lpzlongpath:Byte Ptr, cchbuff:Int) = "GetLongPathNameW@12" End Extern EDIT: found this code by leadwerks (for b+) 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 I am fairly certain there is a way in max to do it without using a bank, it just hasn't come to me yet :/ |
| ||
Global temp_dir:String = getenv_("temp") temp_dir = Replace(temp_dir , "~" , "~~") Doesn't that work ? |
| ||
Huh? Ok let me explain this.. This is a short path "C:\DOCUME~1\ADMINI~1\LOCALS~1\" (6 chars then a '~1'; Generally used for programs that accept appargs, the args are separated by spaces, thus a path must not have spaces in it.) This is the above, but in full path format "C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\LOCAL SETTINGS\" (This is what I am trying to get, from a path string determined at runtime, which may vary from computer to computer.) P.S. Escape sequences are only valid/used at compile time, not runtime (and if they were debuglog should have an error when trying to print temp_dir, because as far as I know ~1 is not a valid escape seq), and have nothing to do with what i am attempting to achieve. |
| ||
Try thisPrint GetFullPath(getenv_("temp")) Function GetFullPath:String( shortpath:String) Local buf:Short[1024] GetLongPathNameW( shortpath, buf, buf.Length) Return String.FromWString(buf) EndFunction Extern "win32" Function GetLongPathNameW( lpzshortpath$w, lpzlongpath:Short Ptr, cchbuff:Int) EndExtern |
| ||
Works! thanks. |
| ||
Generally used for programs that accept appargs, the args are separated by spaces, thus a path must not have spaces in it.) Actually -- if you put an argument within quotes then you can have spaces: program.exe something "c:\program files\something\whatever.dat" and the entire c:\program files\something\whatever.dat will still end up in a single AppArgs[]. |
| ||
Yes, I know. |
| ||
I'm more curious why you're getting this path format in the first place... you running DOS? O_o |
| ||
In the event that you can't use the Win32 function (E.g., for some reason you use these paths under Linux or MacOS), try this.Function LongPath$(sp$) Local spa$[] = sp.Replace("/","\").Split("\") Local con$[] Local spp$ = "" Local s$,si% Local po$ For Local i% = 1 To spa.Length-1 spp :+ spa[i-1]+"\" If spa[i].Find("~~") = -1 Then Continue EndIf s = spa[i].ToLower()[..spa[i].Length-2] si = Int(spa[i][spa[i].Length-1..]) con = LoadDir( spp ) For Local p$ = EachIn con po = p p = p.Replace(" ","").ToLower()[..6] If p = s Then si :- 1 If si = 0 Then spa[i] = po Exit EndIf EndIf Next Next spp :+ spa[spa.length-1] Return spp End FunctionIt's hacky, but it should work. |
| ||
you running DOS? O_o Nope, I'm getting an env variable that is in dos format though..Figured I might as well keep support in case it was like that on other computers. |
| ||
Are you running on abandoned windows versions (Win98 / WinME) that you are getting such strange stuff. I always thought since Windows doesn't have a Dos layer underneath anymore, the 8.3 naming storage is only for 16bit fallback capabilities, but not used by itself (I actually even disabled the storage of the 8.3 namings) |