KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Get path to all sub-folders
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: February 5, 2015

Below is a method that will return all sub-folders within a directory.

// Method: UTIL_GET_SUB_FOLDERS
// Parameters
// $1 - Full path of directory
// $2 - Pointer to array to contain results
// ----------------------------------------------------

C_TEXT($1;$path_t;$path1_t;$sep_t;$lastchar_t)
C_POINTER($2;$result_atp)
C_LONGINT($i)
ARRAY TEXT($folders_at;0)

$path_t:=$1
$result_atp:=$2
$sep_t:=Folder separator

FOLDER LIST($path_t;$folders_at)
$lastchar_t:=Substring($path_t;Length($path_t))
If ($lastchar_t=$sep_t)
  $path_t:=Substring($path_t;1;Length($path_t)-1)
End if

For ($i;1;Size of array($folders_at))
  $path1_t:=$path_t+$sep_t+$folders_at{$i}
  APPEND TO ARRAY($result_atp->;$path1_t)
  UTIL_GET_SUB_FOLDERS ($path1_t;$result_atp)
End for


Below is an example of using the method above to find the sub folders of the Parent folder:


C_TEXT($path_t)
ARRAY TEXT($resultArr_at;0)
$path_t:="C:\\Users\\User1\\Parent"
UTIL_GET_SUB_FOLDERS ($path_t;->$resultArr_at)


The result array $resultArr_at will contain the following elements: