Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NUMBER OF FILES IN A DIRECTORY
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00344120
Message ID:
00344322
Views:
47
Nadya,

Here's one, but it doesn't use the API, just plain old VFP code.
LPARAMETERS pcParent, pcDir
* pcParent is the parent directory and pcDir is the directory to be read for other directories
* First we increment the recusion counter
IF EMPTY(pcDir)
   pcDir = ""
ENDIF
lnRecurse = lnRecurse + 1
IF lnRecurse > 20
   * If we are more than 20 levels of recursion deep
   * Decrement the recursion counter
   lnRecurse = lnRecurse - 1
   * If there is a parent cd back to it
   IF NOT EMPTY( pcParent )
      CD ..
   ENDIF
   * Get out of here well before we blow up
   RETURN
ENDIF
* Declare locals
LOCAL laDirs(1,1), lcParent, lcName, lnCount, lcDir, lcCurDir, ;
      laFiles(1), lnGotOne
* If there is a parent
IF NOT EMPTY( pcParent )
   IF EMPTY( pcDir )
      * Set lcDir to the current directory
      lcDir = RIGHT(CURDIR(),RAT("\",CURDIR())+1)
   ELSE
      * Set lcDir to the users selected directory
      lcDir = pcDir &&RIGHT(pcDir,RAT("\",pcDir)+1)
   ENDIF
   CD "&pcDir"
ELSE
   * If there is no parent we are starting with the first directory
   * We will truncate this dirs name and put the actual path in the 
   * RootOfDir property of the form
   lcCurDir = IIF(EMPTY(pcDir),CURDIR(),pcDir)
   THIS.RootOfDir = lcCurDir
   * Now truncate the directory name
   IF LEN(lcCurDir) > 45
      lcDir = "... " + RIGHT(RIGHT(lcCurDir,RAT("\",lcCurDir)+1),45)
   ELSE
      lcDir = lcCurDir
   ENDIF
   * Set up the node name 
   lcName = lcDir+ALLTRIM(STR(lnRecurse,3))
   * Add the node to the treeview
   THISFORM.PageFrame1.Page1.OleControl1.Object.Nodes.add(,1,lcName, lcDir,0)
   * We are now on our way out so decrement the recusion counter
   lnRecurse = lnRecurse - 1
   * This code is processing the root of the tree so we simply return 
   * out of here
   RETURN
ENDIF

* If we are below the first level, get a list of dirs in this dir
ADIR(laDirs,"","D")
IF TYPE( "laDirs(1,1)" ) <> "C"
   * If we have no directories
   * Decrement the recursion counter
   lnRecurse = lnRecurse - 1
   IF NOT EMPTY( pcParent )
      * If there is a parent for this dir switch to it
      CD ..
   ENDIF
ENDIF
* We are done so restore the dir
IF NOT EMPTY( pcParent )
	CD ..
ENDIF
* Decrement the recursion counter
lnRecurse = lnRecurse - 1
* Get out of here
RETURN
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform