Code: Select all
EnableExplicit
; https://www.purebasic.fr/english/viewtopic.php?f=12&t=65159&p=486382&hilit=SplitL#p486382
Procedure SplitL(String.s, List StringList.s(), Separator.s = " ")
Protected S.String, *S.Integer = @S
Protected.i p, slen
slen = Len(Separator)
ClearList(StringList())
*S\i = @String
Repeat
AddElement(StringList())
p = FindString(S\s, Separator)
StringList() = PeekS(*S\i, p - 1)
*S\i + (p + slen - 1) << #PB_Compiler_Unicode
Until p = 0
*S\i = 0
EndProcedure
Procedure.s GetAbsolutePath(Path$)
Protected pos, pos2, tmp, res$, *Result
Protected NewList StringList.s()
SplitL(Path$, StringList(), #PS$)
ResetList(StringList())
While NextElement(StringList())
If StringList() = "."
DeleteElement(StringList())
ElseIf StringList() = ".."
*Result = DeleteElement(StringList())
If *Result
DeleteElement(StringList())
Else
ProcedureReturn Path$
EndIf
EndIf
Wend
Path$ = ""
ForEach StringList()
Path$ + StringList() + #PS$
Next
Path$ = Trim(Path$, #PS$)
ProcedureReturn Path$
EndProcedure
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\Test.png")
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\Test.png")
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\Test.png")
; GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\Test.png")
; GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\Test.png")
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\Test.png")
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\..\Test.png")
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\..\..\Test.png")
Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\.\.\.\Test.png")
Code: Select all
EnableExplicit
Procedure.s GetAbsolutePath(Path$)
Protected pos, pos2, tmp, res$, i
Repeat
pos = FindString(Path$, #PS$ + "." + #PS$)
If pos
Path$ = ReplaceString(Path$, #PS$ + "." + #PS$, #PS$, #PB_String_CaseSensitive, pos, 1)
EndIf
Until Not pos
Repeat
pos = FindString(Path$, #PS$ + ".." + #PS$)
If pos
pos -1
Repeat
tmp = pos2
pos2 = FindString(Path$, #PS$, pos2 + 1)
Debug pos2
; i + 1
; If i > 16
; Break
; EndIf
Until pos2 > pos
If tmp - 1 >= pos + 4
Break
EndIf
Path$ = Mid(Path$, 1, tmp - 1) + Mid(Path$, pos + 4)
Debug Path$
; i + 1
; If i > 16
; Break
; EndIf
EndIf
; Debug pos
Until Not pos
ProcedureReturn Path$
EndProcedure
; Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\Test.png")
; Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\Test.png")
; Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\Test.png")
GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\Test.png")
; GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\Test.png")
; Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\Test.png")
; Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\..\..\..\..\..\Test.png")
; Debug GetAbsolutePath("C:\PureBasic\purebasic-devel\Residents\Windows\.\.\.\Test.png")