March 01, 2021, 10:52:30 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
»
File Utilities
»
[bmx] Directory Factory by JoshK [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bmx] Directory Factory by JoshK [ 1+ years ago ] (Read 643 times)
BlitzBot
Jr. Member
Posts: 1
[bmx] Directory Factory by JoshK [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Directory Factory
Author :
JoshK
Posted :
1+ years ago
Description :
This is an object-oriented replacement for the standard ReadDir() and NextFile() commands. An HTTP directory factory will try to get all the files in a web folder. The folder must not have an index.htm file.
Code :
Code: BlitzMax
Strict
Import
brl.filesystem
Import
brl.HTTPStream
Import
brl.linkedlist
Private
Global
directory_factories:TDirectoryFactory
Public
Function
ReadDirectory:
TList
(
path$
)
Local
factory:TDirectoryFactory=directory_factories
Local
proto$
Local
i=path.Find
(
"::"
,
0
)
If
i>-
1
proto$=path
[
..i
]
.ToLower
(
)
path$=path
[
i+
2
..
]
EndIf
While
factory
Local
list:
TList
=factory.Read
(
proto,path
)
If
list
Return
list
factory=factory._succ
Wend
EndFunction
Type
TDirectoryFactory
Field
_succ:TDirectoryFactory
Method
New
(
)
_succ=directory_factories
directory_factories=
Self
End
Method
Function
Read:
TList
(
proto$,path$
)
If
proto<>
""
Return
path=RealPath
(
path
)
Local
list:
TList
Local
d=ReadDir
(
path
)
If
Not
d
Return
list=
New
TList
Local
file$
Repeat
file=NextFile
(
d
)
If
Not
file
Exit
list.addfirst
(
file
)
Forever
CloseDir d
Return
list
EndFunction
EndType
New
TDirectoryFactory
Type
THTTPDirectoryFactory
Extends
TDirectoryFactory
Function
Read:
TList
(
proto$,path$
)
If
proto<>
"http"
Return
Local
stream:TStream=ReadStream
(
proto+
"::"
+path
)
If
Not
stream
Return
Local
s$
While
Not
stream.Eof
(
)
s:+stream.ReadLine
(
)
+
"~n"
Wend
Return
ExtractHTMLLinks
(
s
)
EndFunction
Function
ExtractHTMLLinks:
TList
(
html$
)
Local
list:
TList
=
New
TList
html=html.tolower
(
)
Local
sarr$
[
]
sarr=html.split
(
"href="
)
For
Local
n=
1
To
sarr.length-
1
Local
sarr2$
[
]
sarr
[
n
]
=sarr
[
n
]
.
Trim
(
)
sarr2=sarr
[
n
]
.split
(
"~q"
)
If
sarr2.length>
1
If
Not
sarr2
[
1
]
.contains
(
"?"
)
list.addfirst
(
sarr2
[
1
]
)
'Print sarr2[1]
EndIf
EndIf
Next
Return
list
EndFunction
EndType
New
THTTPDirectoryFactory
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
File Utilities
»
[bmx] Directory Factory by JoshK [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal