Tech Tip: Utility method to find files
PRODUCT: 4D | VERSION: 14.1 | PLATFORM: Mac & Win
Published On: December 23, 2014
Below is an utility method to search files within a directory and all subdirectories for a certain term.
// Method: Find_Files // Parameters // $1 - Full absolute path of directory to perform search // $2 - Pattern to search for // $3 - Pointer to array that will contain the results // ---------------------------------------------------- C_TEXT($1;$2;$path;$pattern) C_POINTER($3;$resultArr) C_LONGINT($i;$size) C_BOOLEAN($found) ARRAY TEXT($arrFiles;0) $path:=$1 $pattern:=$2 $resultArr:=$3 DOCUMENT LIST($path;$arrFiles;1) $size:=Size of array($arrFiles) For ($i;1;$size) $found:=Match regex($pattern;$arrFiles{$i};1) If ($found) APPEND TO ARRAY($resultArr->;$arrFiles{$i}) End if End for |
Below is an example of using the method to find all .exe files within a certain directory.
ARRAY TEXT($resultArr;0) $path:="C:\\Users\\Username\\Desktop\\Folder1\\" $pattern:=".exe" Find_Files($path;$pattern;->$resultArr) |