January 15, 2021, 06:25:34 PM

### Author Topic: [bb] RelativePath by Neochrome [ 1+ years ago ]  (Read 587 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] RelativePath by Neochrome [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : RelativePath
Author : Neochrome
Posted : 1+ years ago

Description : This code will turn a path to a relative path system

Code :
Code: BlitzBasic
1. Dim Root\$(64)
2. Dim ssFile\$(64)
3.
4.
5. Function GetRelativePath\$(strRoot\$, strFile\$)
6.     Local i%, NewTreeStart%, sRel\$
7.         Local RootCount%, FileCount%
8.
9.     If Left(strRoot, 3) <> Left(strFile, 3) Then
10.         GetRelativePath = strFile
11.         Return ""
12.     End If
13.
14.         buffa\$ = ""
15.         For i=1 To Len(strRoot\$)
16.
17.
18.                 If Mid(strRoot\$,i,1)="" Then
19.                         RootCount% = RootCount% + 1
20.                 Else
21.                         buffa\$ = Mid(strRoot\$,i,1)
22.                         Root\$(RootCount%) = Root\$(RootCount%) + buffa\$
23.                 End If
24.         Next
25.
26.         buffa\$ = ""
27.         For i=1 To Len(strFile\$)
28.
29.
30.                 If Mid(strFile\$,i,1)="" Then
31.                         FileCount% = FileCount% + 1
32.                 Else
33.                         buffa\$ = Mid(strFile\$,i,1)
34.                         ssfile\$(FileCount%) = ssfile\$(FileCount%) + buffa\$
35.                 End If
36.         Next
37.
38.         i=0
39.
40.     While Root(i) = ssFile(i)
41.         i = i + 1
42.     Wend
43.
44.     If i = RootCount% Then
45.         While i <= FileCount%
46.             sRel = sRel + ssFile(i) + ""
47.             i = i + 1
48.         Wend
49.         GetRelativePath = Left(sRel, Len(sRel) - 1)
50.         Return ""
51.     End If
52.
53.     NewTreeStart = i
54.
55.     While i < RootCount
56.         sRel = sRel + ".."
57.         i = i + 1
58.     Wend
59.
60.     While NewTreeStart <= FileCount
61.         sRel = sRel + ssFile(NewTreeStart) + ""
62.         NewTreeStart = NewTreeStart + 1
63.     Wend
64.
65.         Return Left(sRel, Len(sRel) - 1)
66. End Function