KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Copying folder contents programatically
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: May 19, 2006

To copy all files from a folder $1 into $2, use the method provided below. Both $1 and $2 are text variables passed as parameters to the method.

  ` ----------------------------------------------------
  ` Copies all files from folder $1 to folder $2
  ` ----------------------------------------------------

C_TEXT($1;$sourcePath)
C_TEXT($2;$destinationPath)
C_TEXT($sep)
ARRAY TEXT($listOfFiles;0)
C_LONGINT($i;$platform)
$sourcePath:=$1
$destinationPath:=$2

PLATFORM PROPERTIES($platform)

Case of

  : ($platform=Windows )

    $sep:="\\"

  Else

    $sep:=":"

End case

DOCUMENT LIST($sourcePath;$documents)

If (Test path name($destinationPath)#0)

  CREATE FOLDER($destinationPath)

End if

For ($i;1;Size of array($documents))

  COPY DOCUMENT($sourcePath+$sep+$documents{$i};$destinationPath+$sep+$documents{$i})

End for