Log In    |    Knowledge Base    |    4D Home
Tech Tip: Updating a database with a Batch file
PRODUCT: 4D Developer | VERSION: 11 | PLATFORM: Win
Published On: February 6, 2008

When working with different versions of a database structure between the developer and end user it can be necessary to make changes to the file names or file structure, external from 4D. This is generally necessary when a file that is open by the database needs to be renamed or deleted. On a Windows machine that can be done with a batch file that is run by 4D's LAUNCH EXTERNAL PROCESS command. The following code creates the batch file and runs it:

PLEASE NOTE: this batch file deletes the structure file of the current database!!!

$CRLF:=Char(Carriage return )+Char(Line feed )
$path:=Get 4D folder(Extras Folder )+"dbupdater.bat"

$content:="ping -n 11 >NUL"+$CRLF
$content:=$content+"del \""+Structure file+"\""+$CRLF
$content:=$content+"START \"Title\" /MAX \""+Application file+"\""+$CRLF

$doc:=Create document($path)
SEND PACKET($doc;$content)


$command:="cmd.exe /Cstart \"Title\" \""+$path+"\""



Looking at the content sent to the dbupdater.bat document there are four functions written into the batch file:

  • "ping -n 11 >NUL"
    The ping command is used as a 10 second pause so that 4D can quit before the rest of the batch file runs.
  • "del \""+Structure file+"\""
    This function deletes the current database's structure file. This is why the pause must be in place. The QUIT 4D command called immediately after LAUNCH EXTERNAL PROCESS must have run and quit the 4D application before this works.
  • "START \"Title\" /MAX \""+Application file+"\""
    This function starts the 4D Application that was running the database before, so the user can choose the new database structure to open and reopen it.
  • "Exit"
    This function exits out of the command line window that was opened by LAUNCH EXTERNAL PROCESS.

Another important thing to note in the batch file is that a carriage return and line feed must be called between each command line function to be run.

In this example the structure file is removed, but no replacement is provided. For a more robust example of a batch file used to upgrade 4D databases see the "upgclnt.bat" file in the "4D Extensions" folder of 4D Client on Windows. Additionally, a script file for Mac can be found in the "4D Extensions" folder of 4D Client on MacOS. These script files are used for the automatic client update feature.