January 15, 2021, 06:25:34 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] RelativePath by Neochrome [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
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
eg. GetPath("c:windowssystemdrivers","c:windowseadme.txt")
will return "....eadme.txt"
Code :
Code: BlitzBasic
Dim
Root$
(
64
)
Dim
ssFile$
(
64
)
Function
GetRelativePath$
(
strRoot$, strFile$
)
Local
i%, NewTreeStart%, sRel$
Local
RootCount%, FileCount%
If
Left
(
strRoot,
3
)
<>
Left
(
strFile,
3
)
Then
GetRelativePath = strFile
Return
""
End If
buffa$ =
""
For
i=
1
To
Len
(
strRoot$
)
If
Mid
(
strRoot$,i,
1
)
=
""
Then
RootCount% = RootCount% +
1
Else
buffa$ =
Mid
(
strRoot$,i,
1
)
Root$
(
RootCount%
)
= Root$
(
RootCount%
)
+ buffa$
End If
Next
buffa$ =
""
For
i=
1
To
Len
(
strFile$
)
If
Mid
(
strFile$,i,
1
)
=
""
Then
FileCount% = FileCount% +
1
Else
buffa$ =
Mid
(
strFile$,i,
1
)
ssfile$
(
FileCount%
)
= ssfile$
(
FileCount%
)
+ buffa$
End If
Next
i=
0
While
Root
(
i
)
= ssFile
(
i
)
i = i +
1
Wend
If
i = RootCount%
Then
While
i <= FileCount%
sRel = sRel + ssFile
(
i
)
+
""
i = i +
1
Wend
GetRelativePath =
Left
(
sRel,
Len
(
sRel
)
-
1
)
Return
""
End If
NewTreeStart = i
While
i < RootCount
sRel = sRel +
".."
i = i +
1
Wend
While
NewTreeStart <= FileCount
sRel = sRel + ssFile
(
NewTreeStart
)
+
""
NewTreeStart = NewTreeStart +
1
Wend
Return
Left
(
sRel,
Len
(
sRel
)
-
1
)
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] RelativePath by Neochrome [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal