Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recursive function for directory read
Message
From
03/05/2001 04:39:26
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00502783
Message ID:
00502897
Views:
23
>There are 2 examples in the FoxPro MSDN knowledgebase.
>
>SAMPLE: How to List Directories on Entire Drive
>ID: Q139964
>
>File Search User-Defined Function (UDF) Example
>ID: Q117216
>
But Neil,
Don't you think especially first one's code is too expensive to populate a tree ? I wouldn't like to wait for years to see treeview or outline populates (not commenting on little code error there).
I have a similar code for treeview using FileSystemObject in order to access to directories that VFP cannot by ADIR(). It populates all drives and dirs in just few secs (loosing time on slow diskette drive, CDROM and DVD). My logic was very similar with this addition :
-if a folder have childs just put a dummy node in order to show + sign
-populate childs only if it's expanded (and first time expanded)
Well to be more specific here is code partially snipped :
*-- Fill the tree values
Procedure filltree
  Lparameters tcDirectory, tcType
  This.show
  oNode=THIS.oleTreeview.nodes.add(,tvwFirst,left(tcDirectory,1)+'_Drive',tcDirectory,tcType)
  This._SubFolders(oNode)
  This.olecontrol2.panels(1).text = "Ready"
Endproc

*-- Collect subfolders
Procedure _SubFolders
  Lparameters oNode
  Local nChild, oNodex
  lcFolder = oNode.Fullpath
  lcFolder = strtran(lcFolder,":\\",":\")
  oFS = CREATEOBJECT('Scripting.FileSystemObject')
  oFolder = oFS.GetFolder(lcFolder)
  With ThisForm.oleTreeview.nodes
    If oNode.Children > 0
      If oNode.Child.Key = oNode.Key+"dummy"
        .Remove(oNode.Child.Index)
        nChild = 1
        For each oSubFolder in oFolder.Subfolders
          oNodex = .Add(oNode.Key, tvwChild, ;
            oNode.Key+padl(nChild,3,"0"), oSubFolder.name, "ClosedFolder", "OpenFolder")
          If oSubFolder.Name # "System Volume Information" and oSubFolder.Subfolders.Count > 0
            oNodex = .Add(oNode.Key+padl(nChild,3,"0"), tvwChild, ;
              oNode.Key+padl(nChild,3,"0")+"dummy", "Loading...", "ClosedFolder" )
          Endif
          nChild = nChild+1
        Endfor
      Endif
    Else
      If oFolder.Subfolders.count > 0
        oNodex = .Add(oNode.Key, tvwChild, ;
          oNode.Key+"dummy", "Loading...", "ClosedFolder" )
      Endif
    Endif
  Endwith
Endproc


Procedure Init
  oFS = CREATEOBJECT('Scripting.FileSystemObject')
  For Each Drive In oFS.Drives
    Do case
      Case Drive.DriveType = 0
        lcType = 'Unknown'
      Case Drive.DriveType = 1
        lcType = 'Floppy'
      Case Drive.DriveType = 2
        lcType = 'Drive'
      Case Drive.DriveType = 3
        lcType = 'Netdrive'
      Case Drive.DriveType = 4
        lcType = 'CDdrive'
      Case Drive.DriveType = 5
        lcType = 'Ramdrive'
    Endcase
    If Drive.IsReady
      This.filltree(Drive.DriveLetter+":\", lcType)
    Endif
  Endfor
Endproc


Procedure oleTreeview.Expand
  *** ActiveX Control Event ***
  Lparameters node
  Thisform._SubFolders(node)
  Node.ensurevisible
Endproc
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform