Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'FastTreeBuffer.bas 2021 08/08 (originally: "sTreeDir.bas")
- '===
- 'This FreeBASIC program module was created my Mysoft and updated by Timothy Keal.
- 'It is intended to be coupled with the "Mustang" Expansion Pack.
- '===
- 'In summary: (What "FastTreeBuffer" Does)
- '1. Accepts a valid path within local file storage as input
- '2. Crawls all the contained files and subfolders
- '3. Gathers a cumulative list of all found items
- '4. Proceeds each with a tag indicating whether the entry corresponds to a directory or a file
- '5. Returns result as a string with each result separated by carriage-return/linefeeds
- '===
- 'For more information visit http://puzzlum.net/
- #lang "fb"
- #include "dir.bi"
- declare function FastTreeBuffer( sFolder as string , sOutput as string = "" ) as string
- print FastTreeBuffer(exepath)
- sleep
- function FastTreeBuffer( sFolder as string , sOutput as string = "" ) as string
- const PathSep = "\\", PathWild = "*", PathNav = "."
- const FolderPrefix = "DIR", FolderSuffix = ""
- const FilePrefix = "FIL", FileSuffix = ""
- const PrefixSep = "=", SuffixSep = ""
- const crlf = chr(13)+chr(10)
- dim as integer iAtt,iReturn=len(sOutput)=0
- dim as string sFolders
- var s = dir(sFolder+PathSep+PathWild,-1,iAtt)
- while len(s)
- if s[0]=asc(PathNav) then
- if s[1]=0 orelse (s[1]=asc(PathNav) andalso s[2]=0) then
- s = dir(iAtt) : continue while
- end if
- end if
- if (iAtt and fbDirectory) then
- if len(sOutput)>0 then sOutput += crlf
- sFolders += s+chr(0) : sOutput += FolderPrefix+PrefixSep+sFolder+PathSep+s+SuffixSep+FolderSuffix
- else
- if len(sOutput)>0 then sOutput += crlf
- sOutput += FilePrefix+PrefixSep+sFolder+PathSep+s+SuffixSep+FileSuffix
- end if
- s = dir(iAtt)
- wend
- sFolders += chr(0)
- dim as zstring ptr pzFolder = strptr(sFolders)
- do
- var iLen = len(*pzFolder)
- if iLen = 0 then exit do
- FastTreeBuffer( sFolder+PathSep+*pzFolder , sOutput )
- pzFolder += iLen+1
- loop
- if iReturn then return sOutput
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement