KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Populating the path to all subdirectory levels
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: December 13, 2002
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Compatibility: Version 6.7 and 6.8


The command FOLDER LIST populates the Text or String array directories with the names of the subdirectories located in a specific pathname. However, there is no command in 4D that will populate a text or string array of all subdirectories, including all subdirectory levels. Here is a method that will perform this task for you.

` Project Method: Get_All_Directories
` Description: Obtain the subdirectories of all levels from a given path
` $1 - Pathname to volume, directory or folder
` $2 - Pointer to an empty text array
`
` Return: Full path of the directories (all sub-levels) that resides within $1

C_TEXT($1;$vtTargetPath)
C_POINTER($2;$pa_rootdir)
$vtTargetPath:=$1
$pa_rootdir:=$2

INSERT ELEMENT($pa_rootdir->;1;1)
$pa_rootdir->{1}:=$vtTargetPath

C_LONGINT($platform;$system;$machine;$next)
PLATFORM PROPERTIES($platform;$system;$machine)
If ($platform=3)
 $sep:="\"
Else
 $sep:=":"
End if

$next:=0

Repeat
 $next:=$next+1

 ARRAY TEXT($subdirectories;0)
 FOLDER LIST($pa_rootdir->{$next};$subdirectories)

 For ($i;1;Size of array($subdirectories))
  $vlElem:=Size of array($pa_rootdir->)+1
  INSERT ELEMENT($pa_rootdir->;$vlElem)
  $pa_rootdir->{$vlElem}:=$pa_rootdir->{$next}+$subdirectories{$i}+$sep
 End for

Until ($next>=Size of array($pa_rootdir->))

DELETE ELEMENT($pa_rootdir->;1;1)