Advertisement
jargon

FastTreeBuffer()

Aug 8th, 2021 (edited)
3,228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'FastTreeBuffer.bas 2021 08/08 (originally: "sTreeDir.bas")
  2. '===
  3. 'This FreeBASIC program module was created my Mysoft and updated by Timothy Keal.
  4. 'It is intended to be coupled with the "Mustang" Expansion Pack.
  5. '===
  6. 'In summary: (What "FastTreeBuffer" Does)
  7. '1. Accepts a valid path within local file storage as input
  8. '2. Crawls all the contained files and subfolders
  9. '3. Gathers a cumulative list of all found items
  10. '4. Proceeds each with a tag indicating whether the entry corresponds to a directory or a file
  11. '5. Returns result as a string with each result separated by carriage-return/linefeeds
  12. '===
  13. 'For more information visit http://puzzlum.net/
  14.  
  15. #lang "fb"
  16.  
  17. #include "dir.bi"
  18.  
  19. declare function FastTreeBuffer( sFolder as string , sOutput as string = "" ) as string
  20.  
  21. print FastTreeBuffer(exepath)
  22. sleep
  23.  
  24. function FastTreeBuffer( sFolder as string , sOutput as string = "" ) as string
  25.     const PathSep = "\\", PathWild = "*", PathNav = "."
  26.     const FolderPrefix = "DIR", FolderSuffix = ""
  27.     const FilePrefix = "FIL", FileSuffix = ""
  28.     const PrefixSep = "=", SuffixSep = ""
  29.     const crlf = chr(13)+chr(10)
  30.    
  31.     dim as integer iAtt,iReturn=len(sOutput)=0
  32.     dim as string sFolders
  33.     var s = dir(sFolder+PathSep+PathWild,-1,iAtt)
  34.     while len(s)
  35.         if s[0]=asc(PathNav) then
  36.             if s[1]=0 orelse (s[1]=asc(PathNav) andalso s[2]=0) then
  37.                 s = dir(iAtt) : continue while
  38.             end if
  39.         end if
  40.         if (iAtt and fbDirectory) then    
  41.             if len(sOutput)>0 then sOutput += crlf
  42.             sFolders += s+chr(0) : sOutput += FolderPrefix+PrefixSep+sFolder+PathSep+s+SuffixSep+FolderSuffix
  43.         else    
  44.             if len(sOutput)>0 then sOutput += crlf
  45.             sOutput += FilePrefix+PrefixSep+sFolder+PathSep+s+SuffixSep+FileSuffix
  46.         end if
  47.         s = dir(iAtt)    
  48.     wend
  49.     sFolders += chr(0)
  50.     dim as zstring ptr pzFolder = strptr(sFolders)
  51.     do
  52.         var iLen = len(*pzFolder)
  53.         if iLen = 0 then exit do
  54.         FastTreeBuffer( sFolder+PathSep+*pzFolder , sOutput )
  55.         pzFolder += iLen+1
  56.     loop
  57.     if iReturn then return sOutput
  58. end function
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement